In: Computer Science
Write a C++ program that reads integers from standard input until end of file.
Print out the largest integer that you read in, on a line by itself.
Any erroneous input (something that is not an integer) should be detected and ignored.
In the case where no integers are provided at all, print NO INTEGERS and stop
Remember, try not to do the entire job all at once! First try input of a single number and make sure it works. Make sure that you detect eof correctly. Then add the error checks. Then add the loop...
If you have any doubts, please give me comment...
#include<iostream>
using namespace std;
int main(){
int num, largest, n;
n = 0;
cin>>num;
while(!cin.eof()){
if(n==0)
largest = num;
if(largest<num)
largest = num;
n++;
cin>>num;
}
if(n==0)
cout<<"NO INTEGERS"<<endl;
else
cout<<"Largest: "<<largest<<endl;
return 0;
}