Need Help

I have an infinite loop going on but I cant think of what or how to get out of it. I am trying to have the program take integers and add them up until the sum is 35.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
void main()

{

	int Number, Sum;

	Sum = 0;

	cout << "Enter a Positive number ==> ";

	cin >> Number;


	Sum = Sum + Number;

	while (Sum <= 35)

	{
		

	cout << "enter another number ==> ";

	cin >> Number;
}
	
		if (Sum > 35)

			cout << "Sum is over 35!";

  
place the code Sum= Sum + Number; inside the while loop.
Thank you!
The loop is infinite because when the sum is greater than 35, you output "Sum is over 35!", but you dont end the loop. Add a "break;" to it. Or you can use a "return;" if you want the end the function/program.


Also: the main function should always return an int, ie:

int main(){
// stuff
return 0;
}
Topic archived. No new replies allowed.