MHB How many times should the value of inputCount be read?

  • Thread starter Thread starter Chrisanchez
  • Start date Start date
  • Tags Tags
    Format Integers
AI Thread Summary
The discussion centers on a coding issue related to reading an integer input count and subsequently reading that many integers to output them in a specific format. The main problem arises from the code's logic, which leads to the last integer being repeated multiple times in the output. The user is confused about how many times the program should read the input count based on the problem statement, which specifies reading an initial value for `inputCount` and then reading that many integers. The user believes the program should read the input count only once and then read the specified number of integers, but the current implementation incorrectly reads the last integer repeatedly. Clarification is sought on the interpretation of the problem statement, particularly regarding how many times `inputCount` should be read and the expected output format. The user emphasizes the need for precise quotes from the problem statement to support their understanding of the requirements.
Chrisanchez
Messages
3
Reaction score
0
First, read in an input value for variable inputCount. Then, read inputCount integers from input and output each integer on a newline after the string "value - ".
Ex: If the input is 2 25 55, the output is:
value - 25
value - 55
Code:
#include <iostream>
using namespace std;

int main() {
int inputCount;
int i;
cin >> inputCount;
for(i=0; inputCount > i | | inputCount < i; ++i){
cin >> inputCount;
cout << "value - " << inputCount << endl;
}
return 0;
}
I'm having trouble figuring out what I'm doing wrong, I able to get the output that I wanted but it keeps repeating the last output that is needed. for example the output that I'm getting is "value - 25 value - 55 value -55 . . ." and it keeps repeating the last output.
 
Technology news on Phys.org
How many times should the program read inputCount according to the problem statement? How many times does your program read inputCount?
 
Evgeny.Makarov said:
How many times should the program read inputCount according to the problem statement? How many times does your program read inputCount?
It should read inputCount 2 times and output the values after the initial stated amount of times. for example the values are 3, 20, 26, -20. So it should read the 3 as how many times down the list it should output, for example the code output should be 20, 26, -20. But my code for some reason, i do not know, will read the last value, -20, and continue to repeat it for more than 10 times when I need it to read it once.
 
Chrisanchez said:
It should read inputCount 2 times
Please convince me that the problem statement really says this. Show me the exact quote and explain why you think the program should read the value of inputCount two times. I suggest using short and clear sentences.
 
Evgeny.Makarov said:
Please convince me that the problem statement really says this. Show me the exact quote and explain why you think the program should read the value of inputCount two times. I suggest using short and clear sentences.
This is the question that they are asking me:
First, read in an input value for variable inputCount. Then, read inputCount integers from input and output each integer on a newline after the string "value - ".
Ex: If the input is 2 25 55, the output is:
value - 25
value - 55
 
I have already read the problem statement in post #1. There is no need to repeat it. I asked you to provide a small quote that says that the value of inputCount should be read twice. Do you agree, for example, that the phrase 'output each integer on a newline after the string "value - "' has nothing to do with reading inputCount? Then why do you quote it? Please quote only the relevant part that says how many times inputCount should be read. Also describe how you interpret that quote, why do you think it says what is says.
 
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...
Back
Top