I just starting learning C++. Here is my code:
#include <iostream>
using namespace std;
int main() {
double hours,rate,pay;
// get the number of hours worked
cout << "How many hours did you work?";
cin>> hours;
//Get the hourly pay rate
cout<<"How much did you get paid per hour?";
cin>> pay;
// calculates the pay
pay = hours * rate;
// Display the pay
cout<<"You have earned $" << pay <<endl;
return 0;
}
How many hours did you work?19
How much did you get paid per hour?15
You have earned $4.03179e-313
I think your
cin >> pay line is wrong, because you follow it up with
pay = hours * rate. Since rate is never assigned to, it just gets junk data in memory, so the output is undefined. Change
cin >> pay to
cin >> rate