Sum of numbers (looping lab)

Hey everyone, I've been working on this lab for my CS1 class the last few days and I'm embarrassed to say I'm completely stumped and it's only the third week.

This is the exact problem:
"Your program should ask the user for a sequence of numbers until the user inputs 0 (zero) and then the program should print the sum of positive numbers that the user input. Here is an example dialog:

Input sequence of integers (zero to stop): -4 3 -20 10 45 100 -1 0
The sum of positive numbers is: 158

You are not allowed to use functions, arrays or other constructs that we have not yet studied."

I was easily able to make a program to get the sum of two numbers and a few more but I need it to be capable of inputting an infinite amount of numbers and I have no clue how. Any hints or answers would be much appreciated. I've been sick that last few weeks and I'm behind so explaining with as much detail as you could would be great. I'm expecting you to write out the code for me (although that'd be lovely) but I'm seriously stumped and very stressed.

Thanks for all the help!
i am writing a bit help for you...

1
2
3
4
5
6
7
8
9
int number;
int sum =0;
do
{
	-> take input for number
	-> if(number > 0)
			sum + = number;
}while(number!=0)
->print you sum
Last edited on
Topic archived. No new replies allowed.