+ 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; }
7 odpowiedzi
+ 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;
}
+ 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
+ 2
Cheers guys. Expect tonnes of more questions. In the near future. Studying at the moment for my course this Septembet
+ 1
Feel free to ask as we relearn or refresh when respond to questions...
0
Isn"t the cout to the screem displaying "Enter a number" completely optional ?
Where did I go wrong above ?
0
Oh I see. Thanks very much
0
there is an Error in cin b , you should write cin>> b ;
Good luck 👍