Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ Code Help

  1. Jul 25, 2006 #1
    How I can write a program which reads a sequence of integers and counts how many there are. Print the count. For example, with input 55 25 1004 4 -6 55 0 55, the output should be 8 because there were eight numbers in the input stream. Please help.
     
  2. jcsd
  3. Jul 25, 2006 #2

    0rthodontist

    User Avatar
    Science Advisor

    Can you write a program that just reads integers until there aren't any more, then stops?
     
  4. Jul 25, 2006 #3
    Count the spaces
     
  5. Jul 25, 2006 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Use a while loop, the cin.eof() function, and a counter variable.

    - Warren
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C++ Code Help
Loading...