I am new to c++ and I have been having a hard time understanding the following program. it looks so simple and so it made me feel like I am wrong about everything I have learn so far in c++.
int number = 0;
int min = 0;
cout << "enter (-1) to stop" << endl;
while( number != -1)
{
cout << "Enter an integer:";
cin >> number ;
if (number < min)
min = number;
}
cout << "your minimum number is: " << min << endl;
what I am mostly confused about is the if statement. "min" has only been initialized as equal to zero so the entire if statement does not make sense to me. there is nothing that really defines "min" in the program in my opinion. Any contribution is much appreciated. thank you!
the program does work fine. And, indeed it does find the minimum of a set of numbers that a user enters. I just do not understand how that happens
minbeing flawed (it should be initialized to a very large number, typicallystd::numeric_limits<int>::max()), I'm not entirely sure what you mean. Can you please try to elaborate on the problem or your question? What do you mean with "there is nothing that really defines "min" in the program"?-1, and that is also considered as one of the numbers.