Qtcreator won't calculate correctly
I have the following console program on qtcreator 4.7.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a;
int b;
int result = a * b;
cout<<"Enter a";
cin>>a;
cout<<"Enter b";
cin>>b;
cout<<"You entered"<<a<<"and you entered"<<b<<"Their product is"<<result<<endl;
cout << "Press any key to exit..." << endl;
system ("pause");
return 0;
}
When i input 5 and 9,i get You entered5and you entered9Their product is-2009147472
why am i not getting 45?.
Re: Qtcreator won't calculate correctly
Hm, that's just a guess, but maybe you should calculate the result after the user has entered the numbers...
Re: Qtcreator won't calculate correctly
Thanks,that was the problem.
Code:
cout<<"Enter a";
cin>>a;
cout<<"Enter b";
cin>>b;
int result = a * b;
worked.
Re: Qtcreator won't calculate correctly
This question has precisely nothing to do with either Qt or Qt creator.
For future reference, the language you are writing code in is called C++.