Simple variable use in C++
//My compiler is dev c++
//Second snippet made
#include <iostream>
using namespace std;
int z;
int main(){
int x;
int y;
cout << "Type a number. ";
cin >> z;
cout << "Type another. ";
cin >> x;
z = x*y;
cout << "The two you entered multiplied is " << z << "\n";
system("pause");
}
@ChunkieMonkey
in my opinion your declaring Z as your 1st number and X as 2nd number but your condition said Z=X*Y.. better change your inputs very well..that's all.
and for you Zmodem
using namespace std;
int main()
{
int num1,num2,product;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
product = num1 * num2;
cout << "The product is: " << product << endl;
system("pause");
return 0;
}
better change it dude..
int num1,num2,product;>>> to double num1,num2,product;
cause integers are declaring only a single variable..
Just like to toss in my two cents, so bear with me.
A major contradiction in programming is using meaningful variable names, which, in this case, make no sense at all. Why not use names like: num1, num2 & product? Anyways, I'm using Visual Studio 2008 and when I compile this code, I always get a product response of:
The two you entered multiplied is 0
No matter what numbers I've entered, the product is always 0. The reason for this is quite obvious, as everyone has already stated that your variables are all mixed up and in the wrong spot. In any case, something to the correct deter would be:
#include <iostream>
using namespace std;
int main()
{
int num1,num2,product;
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
product = num1 * num2;
cout << "The product is: " << product << endl;
system("pause");
return 0;
}