For some reason, the second time this loop is iterated, the cout statements overlap. In other words, after the first cout, the program does not wait for an input. How do I solve this?
Also, in the case of real life taxes, does the nPay func work right? Someone told me that the taxes should be multiplied by gross, eachindividually, and added. However, my method would work the same, especially since they occur simultaneously.
double calcGrossPay (double payRate, double hours);
double nPay (double& fedTx, double& localTx, double& stateTx, double& ssTx, double& netPay, double fPay);
void displayAll (double fPay, double netPay, string name);
double fedTx = 14, stateTx = 6, localTx = 3.5, ssTx = 4.75;
int main()
{
while (!cin.eof())
{
string name;
//cin.ignore();
cout <<"Please enter your working name: ";
getline (cin, name);
!cin.eof();
double payRate, hours;
cout <<"Enter your pay rate and hours worked, respectively."<< endl;
cin >> payRate >> hours;
!cin.eof();
double fPay = calcGrossPay (payRate, hours);
double netPay = 0;
netPay = nPay (fedTx, localTx, stateTx, ssTx, netPay, fPay);
displayAll (fPay, netPay, name);
system("pause");
}
}
double calcGrossPay (double payRate, double hours)
{
double extraT, fPay;
if (hours > 40)
{
extraT = (hours - 40) * (1.5 * payRate);
fPay = extraT + (40 * payRate);
}
else
fPay = payRate * hours;
return fPay;
}
double nPay (double& fedTx, double& localTx, double& stateTx, double& ssTx, double& netPay, double fPay)
{
double totalTx = fedTx + localTx + stateTx + ssTx;
netPay = fPay * (1 - (totalTx / 100));
return netPay;
}
void displayAll (double fPay, double netPay, string name)
{
cout <<"Below is "<< name << "'s salary information" << endl;
cout << fixed << showpoint << setprecision(2) <<"\nYour calculated gross pay is $"
<< fPay << ", and your net pay is $" << netPay << endl;
}