c++ - How to find sum of several integers input by user using do/while, While statement or For statement -
Please help here. I want to create a program in which a user uses a number of numbers (let's say 6 numbers to 6 numbers). Then the program should proceed and calculate the sum of all these points. I, however, have to use a loop statement, either for a statement, during statement or during statement / statement. This is what I have done so far:
#include & lt; Iostream & gt; using namespace std; Int main () {int count = 1; Int sum = 0; Int number; Int nights; Cout & lt; & Lt; "Enter the number of items: \ n"; Cin & gt; & Gt; Numberitems; Cout & lt; & Lt; Enter the number: \ n "; Cin & gt; & Gt; Number; Do {sum = sum + number; Count ++; } Whereas (calculation
and even using other statements
#include & lt; Iostream & gt; using namespace std; Int main () {int count = 1; Int sum = 0; Int number; Cout & lt; & Lt; Enter the number: \ n "; Cin & gt; & Gt; Number; While (calculation
I know that this is the first luggage, it is a good start, so help a sister humbly. Thank you
For loop works well, I've modified it a little bit:
# include & lt; Iostream & gt; using namespace std; Int main () {int sum = 0; Int number; Int nights; Cout & lt; & Lt; "Enter the number of items: \ n"; Cin & gt; & Gt; Numberitems; For (Int i = 0; I
However, the WHILE loop has found some errors on line 11 (the calculation was not declared in this area). What could be the issue? In addition, if you have a solution using DO, WHILE loop will be amazing thanks
Comments
Post a Comment