The = operator assigns pay the value of whatever hours and rate were at the exact instant that line is computer (simplification), meaning if hours's and rate's values change then pay won't change with them.
Hint: Move that line to somewhere after cin >> rate;.
You have only declared rate and pay at: double hours, rate, pay , you didn't initialize it, but you have used it at pay = hours * rate; . Just move that line to below cin >> rate; .
A variable that is defined but not initialized contains unused memory, or more commonly referred to a garbage. That's the value you're seeing. It's easy to initialize a variable:
1 2 3 4 5 6
int main( )
{
int Var1; // Uninitialized.
int Var2( 0 ); // Initialized.
int Var3 = 0; // Initialized.
}
kcomp11 wrote:
pay=hours*rate;
If you print this, you'll probably get something like this: 7234792. This is because of those uninitialized variables. Initialize them and do what the two previous posts suggested, and you'll be laughin'.