#include #include double total_cost (int burgers, int fries) { if (burgers >= fries) { // all fries cost only 0.75 return (burgers * 2.00) + (fries * 0.75); } // we have more fries than burgers. // each burger and fries combination costs #2.75, // and each extra fries costs $1.00 return (burgers * 2.75) + ((fries - burgers) * 1.00); } int main () { double cost, cost_of_all_orders = 0; int burgers, fries, number_of_orders = 0; // get this out of the way (all output requires the same options) cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2); for (;;) { cout << "Enter burgers and fries (any negative terminates): "; cin >> burgers >> fries; if ((burgers < 0) || (fries < 0)) { break; } cost = total_cost (burgers, fries); cout << "The cost is $" << cost << endl; cost_of_all_orders += cost; number_of_orders++; } if (number_of_orders != 0) { // play it safe cout << "The average order cost is $" << cost_of_all_orders / number_of_orders << endl; } // else not doing anything is a reasonable action }