+ 1

I do not undersand why this program does not works

#include <iostream> using namespace std; int main() { int a, b; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; int sum = a + b cout << sum cout << a << " "<< b; return 0; }

12th Dec 2016, 2:56 PM
Περικλης Κοροντζης
Περικλης Κοροντζης - avatar
4 Antworten
+ 1
thanks a lot
12th Dec 2016, 3:08 PM
Περικλης Κοροντζης
Περικλης Κοροντζης - avatar
+ 1
becoz u wern't define sum previously in input....nd after that u dont semicolon after int sum =a+b;
14th Dec 2016, 4:45 PM
Saurav Shanu
Saurav Shanu - avatar
0
It not working because you did not pre declare the variable" sum", and you made syntax errors The correct code is below. Note the bugs are commented on: #include <iostream> using namespace std; int main() { int a, b, sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b //Bug 1 -> failed to preDeclare sum cout << sum; //Bug 2 -> no semi-colon. cout << " " << a << " "<< b; /* added an extra space, just to differentiate between sum and variable a. */ return 0; }
12th Dec 2016, 3:05 PM
JENN
JENN - avatar
0
cause you forgot semicolmn ';' here : int sum=a+b; coût<<sum;
12th Dec 2016, 3:38 PM
Mehdi Bouzidi
Mehdi Bouzidi - avatar