I wrote a program that should output the maximum int
from user input:
15 20 0 5 -1
should output Max: 20
There seems to be an infinite loop because it never gets to the final cout
statement. The while loop should stop with a negative number. It's not outputting anything right now.
Here is my code:
#include <iostream>
using namespace std;
int main()
{
int currV;
int maxSoFar;
// 15 20 0 5 -1
// should output 20
cin >> currV;
if (currV > 0)
{
maxSoFar = currV;
}
while (currV > 0)
{
if (currV > maxSoFar)
{
maxSoFar = currV;
}
cin >> currV;
}
cout << "Max: " << maxSoFar;
}