// Clay Shields // Solution for 071 Project 1 // Clyde's Carryout Cupcakes #include #include using namespace std; // Start int main() { // define constants for things that won't change value const float cupcake_cost = 2.75; const float dozen_cost = 30.0; const float sprinkles_cost = 0.35; const float discount_rate = 0.15; const float tax_rate = 0.10; // Make space to hold the order amount int number_cupcakes_ordered = 0; int number_sprinkles_ordered = 0; int dozens_of_cupcakes_count = 0; int individual_cupcake_count = 0; // Variables for costs float cost_of_dozens = 0; float cost_of_individuals = 0; float cost_of_sprinkles = 0; float order_total = 0; float tax = 0; float discount = 0; float total_with_discount = 0; float total_with_tax_and_discount = 0; // inputs for discount and taxes char discount_status_in; char tax_status_in; bool get_discount = false; bool pay_taxes = false; // Say what the program does cout << "Welcome to Clyde's Carryout Cupcakes!" << endl; cout << "Please enter the following information:" << endl << endl; // Get user input for what they are buying cout << "Enter the number of cupcakes purchased: "; cin >> number_cupcakes_ordered; // Make sure that the input makes sense if (number_cupcakes_ordered <= 0) { cout << "An order with zero cupcakes is free!" << endl; exit (0); } if (number_cupcakes_ordered > 1200){ cout << "I'm sorry, we don't make that many cupcakes." << endl; exit (0); } // Get user input for number of sprinkles cout << "How many cupcakes had sprinkles: "; cin >> number_sprinkles_ordered; // Make sure that the input makes sense if (number_sprinkles_ordered < 0) { cout << "You can't have a negative number of sprinkles." << endl; exit (0); } if (number_sprinkles_ordered > number_cupcakes_ordered) { cout << "You can't have more sprinkles than cupcakes." << endl; exit (0); } // Calculate the number of dozens and the leftovers dozens_of_cupcakes_count = number_cupcakes_ordered / 12; individual_cupcake_count = number_cupcakes_ordered % 12; // Figure out the costs of the order cost_of_dozens = dozens_of_cupcakes_count * dozen_cost; cost_of_individuals = individual_cupcake_count * cupcake_cost; cost_of_sprinkles = number_sprinkles_ordered * sprinkles_cost; order_total = cost_of_dozens + cost_of_individuals + cost_of_sprinkles; // Ask if there is a discount cout << "Was this order placed before 11:45 (y/n)? "; cin >> discount_status_in; if ((discount_status_in != 'y')&&(discount_status_in != 'Y')&& (discount_status_in != 'n')&&(discount_status_in != 'N')){ cout << "Invalid entry. Please run the program again." << endl; exit (1); } else { if ((discount_status_in == 'y')||(discount_status_in == 'Y')){ get_discount = true; } else { get_discount = false; } } // Calculate discount if (get_discount) { discount = order_total * discount_rate; } else { discount = 0; } total_with_discount = order_total - discount; // Ask if the order is tax exempt cout << "Is this order tax exempt, such as a GU official purchase (y/n)? "; cin >> tax_status_in; if ((tax_status_in != 'y')&&(tax_status_in != 'Y')&& (tax_status_in != 'n')&&(tax_status_in != 'N')){ cout << "Invalid entry. Please run the program again." << endl; exit (1); } else { if ((tax_status_in == 'y')||(tax_status_in == 'Y')){ pay_taxes = false; } else { pay_taxes = true; } } cout << endl << endl; // Calculate taxes if (pay_taxes){ tax = total_with_discount * tax_rate; } else { tax = 0; } total_with_tax_and_discount = total_with_discount + tax; // Make some nicely formatted output cout << fixed << setprecision(2) << endl << endl; cout << "Clyde's Carryout Cupcakes - Thanks for your order!" << endl; if (dozens_of_cupcakes_count != 0) { cout << setw(25) << "Dozens ordered: " << setw(5) << dozens_of_cupcakes_count << " @ $" << cost_of_dozens << endl; } if (individual_cupcake_count != 0){ cout << setw(25) << "Individual cupcakes: " << setw(5) << individual_cupcake_count << " @ $" << cost_of_individuals << endl; } if (number_sprinkles_ordered != 0){ cout << setw(25) << "Cupcake sprinkles: " << setw(5) << number_sprinkles_ordered << " @ $" << cost_of_sprinkles << endl; } cout << setw(25) << "Subtotal: " << setw(9) << "$" << order_total << endl << endl; if (get_discount) { cout << setw(25) << "Early bird discount: " << setw(9) << "-$" << discount << endl; cout << setw(25) << "Subtotal with discount: " << setw(9) << "$" << total_with_discount << endl; } cout << setw(25) << "Tax: " << setw(9) << "$" << tax << endl << endl; cout << setw(25) << "Please pay: " << setw(9) << "$" << total_with_tax_and_discount << endl; // end return 0; }