0

What is wrong in it. Please explain

#include <iostream> using namespace std; int main() { int a ; int b ; int sum = a + b; cout <<"the sum of a+b is"; cin>>sum; cout << sum; return 0; }

4th Oct 2020, 5:14 PM
AJAY gurjar
AJAY gurjar - avatar
4 odpowiedzi
+ 1
Cin means character input Cout means character output So you print "the sum of a+b" as a string then cin takes the value of sum and then cout prints the value of sum
4th Oct 2020, 5:35 PM
D_Stark
D_Stark - avatar
+ 1
D_Stark, AJAY gurjar you may think of cin as character in, and cout as character out, but officially: cin means console input cout means console output
6th Oct 2020, 6:46 PM
Brian
Brian - avatar
0
What is cin
4th Oct 2020, 5:14 PM
AJAY gurjar
AJAY gurjar - avatar
0
You're adding a and b without assigning any values to them. Being local variables, they will contain unknown values. I presume you meant to use cin with a and b rather than sum. E.g. int a, b; cin >> a >> b; int sum = a + b; cout << "the sum of a + b is " << sum;
4th Oct 2020, 5:45 PM
MaddieL
MaddieL - avatar