You are not logged in. Please login at to post your questions!


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?

asked 30 Oct '14, 07:45

ramher237's gravatar image

accept rate: 28%

Your method for taking input is correct.

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


answered 30 Oct '14, 11:58

wittyceaser's gravatar image

accept rate: 16%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 30 Oct '14, 07:45

question was seen: 781 times

last updated: 30 Oct '14, 11:58