Incorrect product with calculator program

So i wrote a multiply-only calculator program, and it functions fine except for that when i attaempt to multiply the two values, it gives me a ridiculous product. here is the code:

#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Please enter two numbers separated by a space:\n";
cin>>a,b;
cout<<"The product of the two numbers is:\n";
cout<<a*b;
system ("PAUSE");
return 0;
}


i tried to muktiply "8" and "2",and the result i got was "18348608" please tell me what is going on. thank you.
Last edited on
std::cin >>a>>b;
Last edited on
thank you so much. there were no errors and the program functions exactly as intended.
Hey I've got a question about your code, what does "system("PAUSE");" do?
The simple answer is that it causes the system to display "Press any key to contine" and then waits for a keypress. This stops the console window closing before you have a chance to see what your program output is.

However, it's generaly regarded as bad practice, see http://www.cplusplus.com/forum/beginner/1988/ for a LONG series of posts related to this, and 'better' alternatives.
Topic archived. No new replies allowed.