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.
#include <iostream>
usingnamespace 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!";
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: