program to read 10 positive integers, until the value
Write a short C++
Summary
C++ Input taking:
The C++ cin object is used to receive input from the standard input device. H. Accepting keyboard. This is an instance of class istream. It is linked to the standard C input stream stdin. The extraction operator (>>) is used with the cin object to read the input. The Extract operator extracts data from the object cin entered using the keyboard.
The positive integers 1, 2, 3, 4... are called natural numbers.
This program takes a positive integer from the user (assuming the user entered n) and prints the values 1+2+3+...+n.
duplicates. The input is read in two places instead of one. Duplicate code creates the possibility of updating one but not the other when you change the program.
more codes. Reads and tests are split over three lines instead of one. This makes it difficult to read and maintain. Possible error. The GCC I/O library used by DevC++ handles this nicely. However, I've used a system that behaves differently in a while (cin) test depending on whether there is a space after the last value. please think about it. The problem is very subtle. How does the I/O system know not to read the space after the last value? Well, it can't really know, so I'll make some assumptions. Not all systems make the same assumptions about how to handle trailing spaces after the last value.
Step by step
Solved in 2 steps with 2 images