// This program calculates the bill for a wedding invitation order // given the particular prices of Pat's Invitation Emporium (PIE, Inc.). #include #include using namespace std; int main(){ // Define constants for set prices // Put them first so that we can find and change them easily const float small_card = 1.49, large_card = 1.79; const float small_backing = 0.39, large_backing = 0.49; const float two_inks = 0.75; const int minimum_order = 30; const float tax_rate = .0475; // Declare and initialize variables int number_of_cards = 0; float card_cost = 0, total_cost = 0, tax = 0, total_w_tax = 0; bool using_small_cards = true; bool using_backing_cards = false; bool using_two_inks = false; char card_size_letter, backing_input, color_input; // // Say what the program does // cout << "This is the PIE, Inc. Wedding Invitation cost calculator" << endl; cout << "Please enter the following information:" << endl << endl; // // Get some nice input from the user // // First, figure out what the card size is cout << "Enter S for small cards or L for large cards: "; cin >> card_size_letter; // Exit early if the letter isn't valid if ((card_size_letter != 's')&&(card_size_letter != 'S')&& (card_size_letter != 'l')&&(card_size_letter != 'L')){ cout << "Invalid size letter. Please run the program again." << endl; exit (1); } // Now set it to large if needed if ((card_size_letter == 'l')||(card_size_letter == 'L')){ using_small_cards = false; } // Second, see if there is a backing card cout << "Will there be a backing card (y/n)?: "; cin >> backing_input; if ((backing_input != 'y')&&(backing_input != 'Y')&& (backing_input != 'n')&&(backing_input != 'N')){ cout << "Invalid entry. Please run the program again." << endl; exit (1); } // Now set the using_backing_card variable if ((backing_input == 'y')||(backing_input == 'Y')){ using_backing_cards = true; cerr << "Backing cards set" << endl; } // Finally, check the number of inks cout << "Will there be a two ink colors (y/n)?: "; cin >> color_input; if ((color_input != 'y')&&(color_input != 'Y')&& (color_input != 'n')&&(color_input != 'N')){ cout << "Invalid entry. Please run the program again." << endl; exit (1); } // Now set the using_two_inks variable if ((color_input == 'y')||(color_input == 'Y')){ using_two_inks= true; cerr << "Color ink set" << endl; } // Ok, now check to make sure that the order size is sane and reasonable // 0ver 30 and a multiple of 10 cout << "How many invitations are needed?: "; cin >> number_of_cards; if ((number_of_cards < 30)||((number_of_cards % 10) != 0)){ cout << "The number of cards ordered must be at least 30," << endl; cout << "and a multiple of 10" << endl; exit(1); } // Now all the input is all in, do the calculations // First, the cost of the card if (using_small_cards){ card_cost = card_cost + small_card; } else { // must be large cards card_cost = card_cost + large_card; } // Second, if there is a backing card // add the backing card costs if (using_backing_cards){ if (using_small_cards){ card_cost = card_cost + small_backing; } else { // must be large cards card_cost = card_cost + large_backing; } } // Third, if there are two ink colors add the cost in if (using_two_inks){ card_cost = card_cost + two_inks; } cerr << "Card cost is: " << card_cost; // Compute the cost of all the cards total_cost = card_cost * number_of_cards; tax = tax_rate * total_cost; total_w_tax = tax + total_cost; // Output the total cost neatly cout << fixed << setprecision(2) << endl << endl; cout << setw(25) << "Card cost subtotal: " << setw(6) << total_cost << endl << setw(25) << "Tax: " << setw(6) << tax << endl << setw(25) << "Total with tax: " << setw(6) << total_w_tax << endl; return 0; }