+ 2
What's wrong with my code?
Help me please. #include <iostream> using namespace std; int main() { int sum = 0; // take input from the user cout << "Enter a number: "; cin >> number; while (number >= 0){ // add all positive numbers sum += number; // take input again if the number is positive cout << "Enter a number: "; cin >> number; } // display the sum cout<< "\nThe sum is " << sum << endl; return 0 }
12 Antworten
+ 5
There's no syntactical errors other than the return 0 must end with semicolon ...But seeing your commenting on the code , ig your program lacks logic .It would be helpful if you have shared the question ...
+ 5
Hyacenth Luyas Read this lesson.This is a self learning platform , So ig you can make it yourself :
https://www.sololearn.com/learn/CPlusPlus/1617/?ref=app
+ 3
I don't think you have declared the number variable.
+ 2
Mygod I didn't see the last part... Anyway thank you for your help.
+ 2
I think it would have been better to use a do-while loop.
+ 2
Thanks for the info
+ 1
Sonic teach me how please.
+ 1
You don't declared any number variable.
0
Ohh from where I can see the two problems are firstly you should declare the variable ....like 0 is an integer....also return 0 must end with a semicolon...
0
Declaration of number variable is absent.
Declare the "number" variable with valid data type first and then use in the code. 👍👍
0
It will works.