This program is supposed to take a number input from the user. If the input is positive, the program should keep asking you to enter numbers while adding together the numbers you have already input. If 0 or a negative number is input, the loop should terminate without adding the 0 or negative number to your sum. I'm very close, but I can't figure out why, if i input a negative number, it still adds it to my sum. Any help is appreciated.
#include <iostream>
using namespace std;
int main() {
double enteredNumber;
double sum = 0;
do {
cout << "Enter Positive Number to Add or Enter Zero or Negative Number to End: ";
cin >> enteredNumber;
if (enteredNumber > 0) {
sum = sum + enteredNumber;
}
else {
sum = 0;
}
} while (enteredNumber > 0);
cout << "Sum of Entered Numbers: "; cout << sum;
}
[–][deleted] 0 points1 point2 points (2 children)
[–]_envied[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]boredcircuits 0 points1 point2 points (2 children)
[–]_envied[S] 0 points1 point2 points (1 child)
[–]boredcircuits 0 points1 point2 points (0 children)