Hello, first time poster - Have been meaning to register for a long time.. But i haven't gotten around to it until now. So expect alot of noob question, hehe.
So i'm writing a simple program that calculates how many earth years x jupiter years would be.
1 jupiter year = 12 earth years.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
using namespace std;
int main()
{
int eyears, jyears;
eyears = jyears * 12;
cout << "Input the number of Jupiter years to convert to earth years: ";
cin >> jyears;
cout << jyears << " years on jupiter is equal to: " << eyears;
cout << "\n";
system("pause");
return 0;
}
| |
The application runs fine, but i'm getting a garbage value instead of whatever jyears*12 is.
I'm missing something really simple here... Any ideas?
Edit: Err, lol. Sorry, that is a very very bad misstake... I'm used to using loops so that variable changes are always updated. Thus i didn't react to
eyears = jyears * 12
actually being translated to 0 * 12.
I've got another question though, why would the compiler make a garbage value out of 0 * 12 instead of actually displaying 0?
Is it because i'm using a variable as the "0" in it?