• 4
• Locked
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.
You can't complete this task, because you're not signed in.
furius72
Level 9 , Milan, Italy
24 October 2022, 11:21
only number "-1" not every negative number .....
Level 8 , Atlanta, United States
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?
Nathan Guidry
Level 6 , Lake Charles, United States
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??
Ryan Palmer
Level 20 , Philadelphia, United States
21 January 2021, 15:31
Does the break make the condition "false" or simply make it exit?
Toka
Level 11 , Dugo Selo, Croatia
21 July 2021, 16:30
make exit
Albert
Level 6 , Hong Kong, Hong Kong
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? */
Toka
Level 11 , Dugo Selo, Croatia
21 July 2021, 16:31
first when entered -1 loop is over
mastere
Level 9 , Rochester, United States
6 November 2020, 14:40
Feel like I have done this one before? Did it reset somehow?
Isher Singh
Level 5 , Bangalore, India
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.
Roman
Level 41
21 August 2020, 05:48
The condition say "-1 should be included in the sum."
Rose
Level 14 , Richardson, United States
21 June 2020, 01:42
hint: (sum = sum + number) should be before the if statement
Nickolas Johnson
Level 8 , St. Louis, United States of America
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.
yehuda b
Level 23 , Beersheba, Israel
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.