这就是我目前的作业,我想知道如何将结果限制为只显示两位小数。
const float minWage = 7.50;
const float numTax = .15;
float numHours = 0.0;
float grossPay = 0.0;
float withHoldTax = 0.0;
float netPay = 0.0;
cout << "Enter the total hours worked" << endl;
cin >> numHours;
grossPay = numHours * minWage;
withHoldTax = numTax * grossPay;
netPay = grossPay - withHoldTax;
cout << "You worked " << numHours << "hours." << endl;
cout << " " << endl;
cout << "Gross Pay is $" << grossPay << endl;
cout << "Tax collected is $" << withHoldTax << endl;
cout << "Net pay is $" << netPay << endl;
return 0;
}
答案 0 :(得分:0)
尝试使用fixed << setprecision(2) <<