What could be simpler and more pleasant than adding numbers? Especially for a robot. Let's write a program where the user enters numbers from the keyboard, and then a special method sums up the entered numbers. And does so until the user gets bored. When the user is bored, he or she enters -1: the program will understand that it's time to wrap things up, and will then display the sum on the screen.
Adding
- 4
Locked
Comments (25)
- Popular
- New
- Old
You must be signed in to leave a comment
furius72
24 October 2022, 11:21
only number "-1" not every negative number .....
0
NaTasia Madison
12 July 2021, 01:40
I am completely lost with this exercise. So we're not taking the 5 user inputs listed? Is it random numbers?
a = 14, sum = 0, sum += a is 14 or is a the sum of all numbers? If so, how?
0
Nathan Guidry
14 May 2021, 18:31
while what is true though?? That's what I'm not 100% about. I got the code correct but I'm not sure what that condition satisfies..
how could it even be false??
0
Ryan Palmer
21 January 2021, 15:31
Does the break make the condition "false" or simply make it exit?
0
Toka
21 July 2021, 16:30
make exit
0
Albert
20 November 2020, 07:04
/* but what if I input 5 lines of -1,
does the question need us to stop at the 1st -1, or,
need us to sum up the 5 lines of -1? */
0
Toka
21 July 2021, 16:31
first when entered -1 loop is over
0
mastere
6 November 2020, 14:40
Feel like I have done this one before? Did it reset somehow?
+1
Isher Singh
18 August 2020, 18:50
There seems to be confusion in the question. Conditions is if user enters -1 then program should stop taking inputs. Does it means that -1 should be added to the sum or it should be signal to stop the program and display the results of the numbers entered till -1 as an input provided.
0
Roman
21 August 2020, 05:48
The condition say "-1 should be included in the sum."
0
Rose
21 June 2020, 01:42
hint: (sum = sum + number) should be before the if statement
0
Nickolas Johnson
5 March 2020, 20:06
This one had me pulling my hair out for a bit until I realized you have to evaluate the keyboard input each time, not the running number that you keep adding to the previous number. After that it was fairly simple.
0
yehuda b
2 December 2019, 22:53
"-1 should be included in the sum"
Didn't include it and got the solution wrong b/c of it.
0