Not getting the desired output in the result. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Not getting the desired output in the result.

This is the code, but I cannot find that mistake. #include <iostream> using namespace std; int main () { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "sum is: " sum << endl; return 0; }

4th Jun 2018, 10:14 AM
Sanjeet
Sanjeet - avatar
10 Answers
+ 4
Jet ^_^ 🇮🇳 Akib Reza a simple mistake by both of you. 😛 Jet has cout << "sum is: " sum << endl; Akib has cout << "sum is: << sum << endl; Correct is cout << "sum is: " << sum << endl;
4th Jun 2018, 10:30 AM
Andre Daniel
Andre Daniel - avatar
+ 7
Akib Reza Even those are also not working,
4th Jun 2018, 10:26 AM
Sanjeet
Sanjeet - avatar
+ 7
Andre Daniel It worked, thanks a lot,😃
4th Jun 2018, 10:31 AM
Sanjeet
Sanjeet - avatar
4th Jun 2018, 10:22 AM
Sanjeet
Sanjeet - avatar
+ 2
cout << "sum is : "<< sum<< endl; also using float for adding values is better if you wanna add decimal points.
4th Jun 2018, 10:20 AM
Akib
Akib - avatar
+ 2
I didn't ask you to copy what i wrote and paste it. It was just the syntax. Didn't check it I was in a bit hurry. Yes it was a typo thanks for correcting it.
4th Jun 2018, 1:19 PM
Akib
Akib - avatar
+ 1
Can you put the code in the sololearn playground and send the link? That way it's easier for us to find the problem and possible solution.
4th Jun 2018, 10:20 AM
Andre Daniel
Andre Daniel - avatar
+ 1
ypu must add <iostream.h>
6th Jun 2018, 11:14 AM
Mohamad Msalme
Mohamad Msalme - avatar
+ 1
#include <iostream> using namespace std; int main () { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "sum is: " << sum << endl; return 0; }
9th Jun 2018, 6:57 AM
Omid
Omid - avatar
+ 1
you forgot the cin.get(); and cin.ignore()
9th Jun 2018, 7:24 AM
Adrian