+ 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!!!
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;
}
+ 1
x is not correct operator in C++. You should use * for multiplying of integers.
int answer = a*b;
+ 1
You can't calculate answer before storing values in a and b
0
Thank you so much! (:



