+ 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; }
4 Antworten
+ 1
thanks a lot
+ 1
becoz u wern't define sum previously in input....nd after that u dont semicolon after int sum =a+b;
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;
}
0
cause you forgot semicolmn ';' here :
int sum=a+b;
coût<<sum;