所以变量hoursWorked
没有初始化。但是,如果我希望它等于用户存储在其中的任何内容,我应该如何初始化它?例如,我想hoursWorked
成为任何人在其中输出的任何内容cin
。这是我的代码:
#include <iostream>
using namespace std;
int main ()
{
//Declare Variables
double hoursWorked;
double payRate;
double incomeBeforeTax;
payRate = 15;
incomeBeforeTax = payRate * hoursWorked;
cout << "Enter hours worked: ";
cin >> hoursWorked;
cout << endl;
cout << incomeBeforeTax << endl;
return 0;
}