C/C++ Counting Integers: Writing a Program

AI Thread Summary
To create a program that reads a sequence of integers and counts them, a while loop can be utilized alongside the cin.eof() function to determine when the input stream ends. The program should initialize a counter variable to track the number of integers entered. As integers are read, the counter increments for each valid input. The final count is printed after the input ends. This approach effectively handles continuous input until no more integers are available, ensuring accurate counting of the total integers provided.
Gumbyboy2006
Messages
1
Reaction score
0
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.
 
Technology news on Phys.org
Can you write a program that just reads integers until there aren't any more, then stops?
 
Count the spaces
 
Use a while loop, the cin.eof() function, and a counter variable.

- Warren
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top