newbie question c++

How will I stop reading input if the test cases are not provided but is assumed that the input is greater than 1. I looked into CodeChef FAQ and it says that using scanf somehow deals with this problem but im afraid I cant use it because in my subject Programming101 we were only taught about cin and cout to deal with input and output and we are expected to follow it.

The problem Im handling right now is calculating the average grade based on point values and units of subject. The sample input goes like this:

A 3

B 5

B+ 3

C 3

but it is assumed that other testcases would involved 5 subjects or more. It is not specified in the problem either. I am thinking of using while(cin >> letterGrade >> units) but I dont know how to stop the reading of input when it comes to the end. Any suggestions?

Your method for taking input is correct.

When there is nothing to be read from STDIN, the while loop will break.

4 Likes