Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Background: You have just opened a small business named “Cool Choices” selling 4 items. Create a menu of choices:
- 1 Vanilla cone - $1.35
- 2 Lemonade - $2.25
- 3 Bubblegum slush - $3.15
- 4 Yogurt breeze - $4.05
- Your program should display the menu of 4 choices. Allow user input for the choice and validate that the user has entered a correct choice. Prompt the user to enter the quantity for this choice and validate that this is a positive number. Calculate the price which includes a sales tax of 8.25%. Display a sales receipt that includes the choice, the price for a single item, the quantity for this item, the total item cost (without tax), the total tax, the total price (including tax) and a “Thanks for your business” type message.
- Develop functions to perform the tasks. Suggestions for function prototypes:
- void DisplayMenu();
- int GetChoice();
- int GetNumberOfItems(int itemChoice);
- double CalculateTotalItemCost(int itemChoice, int numItems);
- double CalculateSalesTax(double totalItemCost);
- void CreateSalesReceipt(int itemChoice, int numItems,
- double totalItemCost, double totalTax,
- double totalPrice);
- Use global constants for the tax rate and the 4 price choices.
- Each function definition should include the following documentation:
- Purpose:
- Pre-Condition:
- Post-Condition:
- For example:
- int GetNumberOfItems(int itemChoice)
- //Purpose: To return the quantity that the customer wants to purchase.
- //Pre-Condition: User has selected one menu item.
- //Post-Condition: Returns the quantity that the customer wants to purchase
- // of the item selected from the menu.
- {
- //declare local variables, if necessary
- int quantity; //select the quantity for this itemChoice
- . . .
- return quantity;
- }
- */
- // o also think i need to code for it to output to file, which i bet i can code, just gotta look at notes that filestream bullshit of.stream(fag.txt
- // ios:app)
- my code;
- #include <iostream> //cin, cout
- #include <iomanip> //setw, setprecision
- using namespace std;
- void DisplayMenu(void);
- void GetChoice(int *);
- void GetNumberOfItems(int *);
- void CalculateTotalItemCost(int, int, double * );
- void CalculateSalesTax(double, double * );
- void CreateSalesReceipt(int , int , double, double);
- int main (void)
- {
- int choice, quantity;
- double rate, cost, total, totaltax;
- cout << fixed << showpoint << setprecision(2);
- DisplayMenu ();
- GetChoice (&choice);
- GetNumberOfItems (&quantity);
- CalculateTotalItemCost(choice, quantity, &cost);
- CalculateSalesTax(cost, &totaltax);
- CreateSalesReceipt(choice, quantity, cost, totaltax);
- return 0;
- }
- void DisplayMenu (void)
- {
- cout << "PLEASE CHOOSE ONE OF THE FOLLOWING: \n\n" ;
- cout << "1. Vanilla Cone - $1.35\n" ;
- cout << "2. Lemonade - $2.25\n" ;
- cout << "3. Bubblegum Slush - $3.15\n" ;
- cout << "4. Yogurt Breeze - $4.05\n" ;
- }
- void GetChoice (int *choicePtr)
- {
- cout << "Please Enter Choice: " ;
- cin >> *choicePtr;
- while ((*choicePtr < 1)) || (*choicePtr > 4 ))
- {
- cout << "Invalid Option.\n Please enter choice" ;
- cin >> *choicePtr;
- }
- }
- void GetNumberOfItems (int *quantityPtr)
- {
- cout << "\nPLEASE ENTER # OF ITEMS: ";
- cin >> *quantityPtr;
- while (*quantityPtr < 1){
- //It said we needed verification,
- cout << "\n invalid selection. Please enter # of items:";
- cin >> *quantityPtr;
- }
- void CalculateTotalItemCost (int choice, int quantity, double *cost)
- double cost = 0;
- {
- if (choice = 1)
- {
- *cost = 1.35 * quantity ;
- }
- if (choice = 2)
- {
- *cost = 2.25 * quantity ;
- }
- if (choice = 3)
- {
- *cost = 3.15 * quantity ;
- }
- if (choice = 4)
- {
- *cost = 4.05 * quantity ;
- }
- }
- void CalculateSalesTax(double cost, double *tax){
- *tax = cost * .0825;
- }
- void CreateSalesReceipt(int item, int quantity, double cost, double tax){
- cout << "\n\nSALES RECIEPT\n";
- cout << "ITEM: ";
- if (item == 1) {
- cout << "Vanilla Cone\n";}
- if else (item == 2) {
- cout << "Lemonade\n";}
- if else (item == 3) {
- cout << "Bubble Gum Slush\n";}
- else {
- cout << "Yogurt Breeze\n";}
- cout << "QUANTITY: "<< quantity ;
- cout << "\nPRICE WITHOUT TAX: " << cost ;
- cout << "\n\nTAX: " << tax;
- cout << "\n-----------------------";
- cout << "\nTOTAL: "<< (cost + tax);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement