Sequential Securities Program

1

I must write a program that displays values sequentially according to the input value, use a variable to store the value entered.

An example of what the program should do
Input Data: Enter a value. 8
Output data: 8.1, 8.12, 8.123, 8.1234, 8.12345, 8.123456, 8.1234567

What must happen in the program is: that at the time of writing any number the following numbers are displayed in a decimal manner but it stops at a lower number than the initial number.

Please help me correct my mistakes.
What I have is this:

#include <iostream>  
#include <stdio.h>  
#include <stdlib.h>  
#include <windows.h>  
#include <math.h>  

 using namespace std;

 int main()

{ float N_inicial, N_final, N, secuencia;  
char valor;

cout<<"\n"; 
cout<<" \t \t Bienvendido/a... \n Secuencia de numeros \n"; 
cout<<"\n"; 

cout<<"Ingrese un valor: \n"; cin>>N_final; 

    {


    secuencia= N_final+N; 
for (float N = N_inicial; N_inicial = N_final-1; N <= N_final);
        {
            cout<<N_final<<(".");
        for ( char valor = 1; 1<=valor; valor++ );
            {
            cout<<valor;
            }

            cout<<endl; 
        }   

    }
}
    
asked by Marianne Stewart 13.09.2018 в 05:51
source

2 answers

0

There are syntax and logic errors. The for do not end in ; , there are some floating keys before secuencia= N_final+N; that have no use. The easiest way to do what you request is, for each iteration, add to the number the iteracion / (10^iteracion) . Or something like this:

6 + 0/(10^0) = 6
6 + 1/(10^1) = 6.1
6.1 + 2/(10^2) = 6.12
6.12 + 3/(10^3) = 6.123
... y así sucesivamente

Because C ++ omits more than 6 decimals, the setprecision statement was used to force the decimals that are requested to be forced

#include <iostream>
#include <math.h> // pow
#include <iomanip> // setprecision

using namespace std;

int main() {
    int N;
    double N_final, secuencia;

    cout << "\n";
    cout << "Bienvendido/a... \n[ Secuencia de numeros ]\n";
    cout << "\n";
    cout << "Ingrese un valor: "; cin >> N_final;

    cout << fixed;
    secuencia = N_final - 1;
    for (N=0; N<=secuencia; N++) {
        N_final = N_final + N/(pow(10, N));
        cout << setprecision(N) << N_final;
        cout<<endl;
    }
    return 0;
}

Another way to solve the problem would be to handle everything as characters, and it will only be concatenated at the end of the string with the number of the iteration.

    
answered by 13.09.2018 / 07:26
source
0

Since you have labeled the question as C ++, you should use the language appropriately:

answered by 13.09.2018 в 08:14