+ 2

What is wrong with this code? C++ (im new to c++)

#include <iostream> using namespace std; int main() { int a; int b; int answer= a×b; cout<< "Please enter 2 numbers"; cin>> a; cin>> b; cout<< answer <<endl; return 0 } Please Help!!!

31st Dec 2016, 11:55 PM
Dinoloco “Dinoloco27” Gamer
Dinoloco “Dinoloco27” Gamer - avatar
4 Answers
+ 2
You should have written this code like this:- #include <iostream> using namespace std; int main() { int a; int b; int answer; cout<< "Please enter a number: "; cin>> a; cout<< "Please enter another number: "; cin>> b; answer=a*b; cout<< "Answer is: "<<answer<<endl; return 0; }
1st Jan 2017, 7:48 AM
Saksham Beniwal
Saksham Beniwal - avatar
+ 1
x is not correct operator in C++. You should use * for multiplying of integers. int answer = a*b;
1st Jan 2017, 12:04 AM
Dragonway
+ 1
You can't calculate answer before storing values in a and b
1st Jan 2017, 1:34 AM
toxicbits
toxicbits - avatar
0
Thank you so much! (:
1st Jan 2017, 12:06 AM
Dinoloco “Dinoloco27” Gamer
Dinoloco “Dinoloco27” Gamer - avatar