0
In my college work, we submit our code to a platform that "corrects" the code automatically (inserts the entries into the code and compares the generated outputs with the template).
To get the entrances, we always use the command cin
.
To illustrate my problem: Suppose I have the following entry:
1 1
2 3
5 8
0 0
And you have to output the sum of each pair of numbers, until the two are 0, which identifies the end of the entries.
The code would be something like:
#include<iostream>
using namespace std;
int main(){
int x,y;
do{
cin >> x;
cin >> y;
if(x != 0 && y != 0){
z = x + y;
cout << z << endl;
}//fim if
}while(x != 0 && y != 0);//fim do.while
return 0;
}//fim main
Now, I need to solve the same problem, however, the end of the entries is marked by the end of the file (as opposed to having the input pair 0.0).
What condition do I have to put in place while(x != 0 && y != 0);
to make it happen?
The command in question is
cin.eof()
– Henrique Schiess Pertussati