#include #include double cost_of_shirts (int shirts) { // each pair of shrts bought costs $18, each extra shirt costs $10 return ((shirts / 2) * 18) + ((shirts % 2) * 10); } int main () { double cost, cost_of_all_orders = 0; int shirts, total_shirts_sold = 0; // get this out of the way (all output requires the same options) cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2); for (;;) { cout << "Enter number of shirts (0 or negative to terminate): "; cin >> shirts; if (shirts <= 0) { break; } cost = cost_of_shirts (shirts); cout << "The cost is $" << cost << endl; cost_of_all_orders += cost; total_shirts_sold += shirts; } if (total_shirts_sold != 0) { // play it safe cout << "Shirts sold at an average price of $" << cost_of_all_orders / total_shirts_sold << endl; } // else not doing anything is a reasonable action }