C ++ Problem with data entry

1

My problem is when doing a new process, everything normal until I re-enter the amount of values to be compared, I ignore the entries of the new values or it does so erratically. How can I fix this?

This is my code.

#include <iostream>

using namespace std;

int o, num, numax, numin, con1, con2;

int main ()    
{
    o=1;
    numax=0;
    numin=0;
    con1=0;

    while(o == 1)       
    {
        do          
        {
            cout << "\n\n\n\t\t\t\t\t\tComparador de valores\n";
            cout << "\t\t\t\t\t      <----------------------->\n\n";
            cout << "\t\t\t\t\t> Cuantos numeros desea comparar? ";
            cin >> con2;
            system ("cls");             
        }           
        while (con2 < 2);

        cout << "\n\n\n\t\t\t\t\t\tComparador de valores\n";
        cout << "\t\t\t\t\t      <----------------------->\n\n";

        do          
        {               
            do              
            {
                cout << "\t\t\t\t\t> Ingrese un numero: ";
                cin >> num;
                cout << "\n";
                if (num<1)
                cout << "\t\t\t\t\t> Ingrese un valor valido\n\n";
            }               
            while (num<1);

            con1++;
            if (num > numax)
                numax = num;
            if (numin == 0)
                numin=num;
            else if (numin > num)
                numin = num;

        }           
        while (con1 < con2);

    cout << "\t\t\t\t\t> El mayor es: ";
    cout << numax << "\n\n";
    cout << "\t\t\t\t\t> El menor es: ";
    cout << numin << "\n\n";
    cout << "\t\t\t\t\t> Desea hacer una nueva operacion?\n\n";
    cout << "\t\t\t\t\t1 Si\n";
    cout << "\t\t\t\t\t2 No\n\n";
    cout << "\t\t\t\t\t> Ingrese una opcion: ";
    cin >> o;

    if (o == 1)
        system("cls");      
    }

    cout << "\n\t\t\t\t\t> Saliendo...\n\n";
    cin.get();
    cin.get();

    return 0;       
}
    
asked by Malthael 08.09.2016 в 21:24
source

1 answer

3

Instead of:

int main ()    
{
    o=1;
    numax=0;
    numin=0;
    con1=0;

    while(o == 1)       
    {
        do          
        {
            cout << "\n\n\n\t\t\t\t\t\tComparador de valores\n";

Try with:

int main ()    
{
    o=1;

    while(o == 1)       
    {
        numax=0;
        numin=0;
        con1=0;

        do          
        {
            con2=0;
            cout << "\n\n\n\t\t\t\t\t\tComparador de valores\n";

Remember to clean the variables before starting each process. You can also choose to use a for loop to request each number, instead of the while , taking advantage of the fact that you can know the number of iterations, thanks to the variable con2 .

    
answered by 09.09.2016 / 01:40
source