Friday 13 September 2013

Running Total Issue

Running Total Issue

I am very new to C++ and am trying to accomplish a program that will
display the following: 1. A Total of all customer bills 2. Total tax
collected 3. A customer count 4. An average customer bill.
The average bill, total tax, & customer count all seem to be working just
fine. It's the totalBill variable that is throwing it off I believe. I'll
attach the code below, I can't figure it out!
#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
When complied it gives the right numbers only is there is one customer, if
more the total will be thrown off. Thanks in advance!

No comments:

Post a Comment