The C++ program is as follows
#include <iostream>
using namespace std;
int main(void) {
/* temporary storage for the incoming numbers */
int number;
/* we will store the currently greatest number here */
int max = -100000;
/* get the first value */
cin >> number;
/* if the number is not equal to -1 we will continue */
while(number != -1) {
/* is the number greater than max? */
if(number > max)
/* yes – update max */
max = number;
/* get next numbet */
cin >> number;
}
/* print the largest number */
cout << "The largest number is " << max << endl;
/* finish the program successfully */
return 0;
}
If I enter some number such as 69 10 -1
. It will work.
But when I enter some char, even I enter -1
, it didn't stop.
For example a a -1 -1 -1
Why?