+ 1

C++ Simple addition calculator not working

Hey guys can someone tell me why my code won't work, keep getting error messages. I'm an absolute beginner and it's only my second day working on C++. It's just an attempt at a simple addition only calculator. #include <iostream> using namespace std; int main () { int a,b; int sum; cin>> a; cout<<"enter another number\n"; cin b; cout<< "sum is:"<<sum<<endl; return 0; }

26th Jul 2018, 3:43 PM
harry
7 Answers
+ 9
harry It should be like this 👇👇👇 #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; }
26th Jul 2018, 3:50 PM
Mohammad Amir Aqeel
Mohammad Amir Aqeel - avatar
+ 3
you had only declared variable called sum...you had not assigned any value to that sum variable... Complier don't know what you are going to store in sum variable... that you were missing... and cout statement to enter number is not must... it is just used as information to user
26th Jul 2018, 4:07 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
Cheers guys. Expect tonnes of more questions. In the near future. Studying at the moment for my course this Septembet
26th Jul 2018, 4:09 PM
harry
+ 1
Feel free to ask as we relearn or refresh when respond to questions...
26th Jul 2018, 4:11 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Isn"t the cout to the screem displaying "Enter a number" completely optional ? Where did I go wrong above ?
26th Jul 2018, 3:54 PM
harry
0
Oh I see. Thanks very much
26th Jul 2018, 4:05 PM
harry
0
there is an Error in cin b , you should write cin>> b ; Good luck 👍
27th Jul 2018, 9:39 AM
Omar
Omar - avatar