我对 C++ 非常陌生,正在尝试完成一个程序,该程序将显示以下内容: 1. 所有客户账单的总数 2. 征收的税款总额 3. 客户数量 4. 平均客户账单。
平均账单、总税额和客户数量似乎都运行良好。我相信是 totalBill 变量把它扔掉了。下面附上代码,看不懂!
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
double mealPrice;
double mealTotal;
double totalBills;
double totalTax;
double mealTax;
double averageBill;
int customerCount = 0;
mealTotal = 0.0;
bool anotherMeal = true;
char response;
while (anotherMeal == true)
{
cout << "Enter price of your meal: ";
cin >> mealPrice;
cout << endl;
customerCount++;
cout << "Another cusotmer? y/n : ";
cin >> response;
cout << endl << endl;
if (response == 'n') anotherMeal = false;
} //End While Loop
mealTax = (mealPrice * 0.0575);
mealTotal = (mealPrice + mealTax);
totalBills = (mealTotal += mealTotal);
totalTax = (mealTax + mealTax);
averageBill = (totalBills / customerCount);
cout << fixed << setprecision(2) << right;
cout << "Total Customer Bills : $ " << setw(8) << right << totalBills << endl;
cout << "Total Tax Collected : $ " << setw(8) << right << totalTax << endl;
cout << "Customer Count : " << setw(16) << right << customerCount << endl;
cout << "Average Customer Bill : $ " << setw(8) << right << averageBill << endl;
cout << endl;
cout << endl;
return 0;
} //End Main
当遵守时,它只给出正确的数字,只有一个客户,如果更多,总数将被抛出。提前致谢!