Find minimum and maximum values input by the user without using an array

  c++

I know in theory that I would, for the maximum, replace the current value with the new integer that the user inputs if it is higher than the latter, and vice versa for the minimum, but I can’t how to make this happen with my code. Essentially I am asking if there is a way for me to compare two integers without storing their data.

This is a bit of the code that I have thus far. I have found the average, the amount, and the sum of the integers entered as well as the amount of even and odd integers. I now just need to show the minimum and maximum integer values.

int main()
{
    int intVal;
    int sum = 0;
    int maxValue = -1;
    int minValue = -1;
    double average = 0;
    int count = 0;
    int evenCount = 0;
    int oddCount = 0;

    cout << endl << "Enter an integer (negative value to Quit):  ";
    cin  >> intVal;
    cout << endl;


    while(intVal >= 0)
    {
        count ++;
        sum += intVal;
    
        if(intVal > 0)
            average = sum / count;
    
        if(intVal % 2 == 0)
            evenCount ++;
        else
            oddCount ++;
       
        cout << "Enter an integer (negative value to Quit):  ";
        cin  >> intVal;
        cout << endl;
     }
}

Source: Windows Questions C++

LEAVE A COMMENT