0

what is wrong with this?

#include <iostream> using namespace std; int main() { int number; int sum = 0; cout << "Enter a number: "; cin >> number; while (number >= 0) { sum += number; cout << "Enter a number: "; cin >> number; } cout << "\nThe sum is " << sum << endl; return 0; }

11th Sep 2022, 10:59 AM
numan
3 Answers
0
In the while loop, number has to be only >0, not equal.
11th Sep 2022, 11:11 AM
marcram
0
Nothing wrong but loop won't stop until you input a negative number...
11th Sep 2022, 11:52 AM
Jayakrishna 🇼🇳
11th Sep 2022, 1:25 PM
Abhay
Abhay - avatar