Counting Integers: Writing a Program

Click For Summary

Discussion Overview

The discussion centers around writing a program to read a sequence of integers and count how many integers are present in the input. The scope includes programming techniques and logic related to input handling and counting mechanisms.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant requests assistance in writing a program that counts integers from a given input sequence.
  • Another participant suggests writing a program that reads integers continuously until there are no more inputs.
  • A third participant mentions the need to count spaces, implying a consideration of how input is parsed.
  • A later reply proposes using a while loop, the cin.eof() function, and a counter variable as a potential solution.

Areas of Agreement / Disagreement

Participants present various approaches and suggestions, but there is no consensus on a single method or solution.

Contextual Notes

Some assumptions about input format and handling may not be explicitly stated, and the discussion does not resolve how to handle different input scenarios or edge cases.

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
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
10
Views
2K
Replies
3
Views
2K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 49 ·
2
Replies
49
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 2 ·
Replies
2
Views
2K