In C++. the functions and loops are making me super confusedwhen trying to use them together.
Girl Scout Cookie Invoice:Write a program that will create an invoice for a customer whopurchased Girl Scout cookies.The program should continually loop on customers
Program InputFor this program, you will be invoicing for 10 different varietiesof Girl Scout cookies. Theprogram should loop on each input prompt for valid userinput.The program should loop until receiving ‘q’ to exit. This offersthe opportunity to havemultiple customer orders entered by the user.Valid input for each customer is name, address, and city, state andzip code followed by theirorder of each of the ten cookies. If the user enters ‘q’, for thecustomer name, the programshould exit.Input validation should be performed on each cookie. The examplebelow illustrates inputvalidation.quantity = -1while ((quantity < min_order) || (quantity >max_order))In the example above, the program will leave the loop only on goodinput. If the user enters anorder for a negative value or more than 10 cookies of a particulartype, the program should re-prompt the user.Girl Scout Cookie InvoiceWrite a program that will create an invoice for a customer whopurchased Girl Scout cookies.The program should continually loop on customersThe program input prompts to the user are (user enters Johnny Goodfor the first and last name):"Order Number: 1""Enter the customers first and last name (or q to quit): ""Enter the Johnny Good's address: ""Enter the Johnny Good’s city, state and zip code: ""Enter the number of Thin Mints (0-10): ""Enter the number of Lemon-Ups (0-10): ""Enter the number of Lemonades (0-10): ""Enter the number of Samoas (0-10): ""Enter the number of Tagalongs (0-10): ""Enter the number of Do-si-dos (0-10): ""Enter the number of Trefoils (0-10): ""Enter the number of Thanks-A-Lot (0-10): ""Enter the number of Toffee-tastic (0-10): ""Enter the number of Caramel Chocolate Chip (0-10): "Program CalculationThe program should calculate the cost of each type of cookie and arunning total and display thecurrent date.• The current date can be obtained by including the followingheader file:#include <ctime>Now, to get the current date, simply:time_t result = time(NULL);dateStr = ctime(&result);• Girl Scout cookies are currently $5.00/box• The program will need to keep a count of the number orders anddisplay the invoice infile named: ab_orders.txt(where a is the first letter of your first name and b is the firstletter of your last name, allin lower case.)• To create a file, you will need to include the fstream headerfile:#include <fstream>The program will need to open the file for writing as in thisexample:// Open the output fileofstream outFile;outFile.open ("gd_orders.txt");
• In the above example the variable outFile was used to use thefile stream object. Now, youcan write the file:outFile << endl;The above example writes a blank line to the output file. Rememberto close the file:outFile.close();Program NotesYou will need to create a function named getCookies(). Thisfunction will prompt the user for thenumbers of cookies desired. As an example:Enter the number of Thin Mints (0-10):The function will loop until the user enters a valid count. In theabove example, the user will needto enter a value of 0 to 10.The function should accept parameters of the prompt and the maximumcookies the user is allowedto order. It should return the quantity of the cookies desired. Asa reminder, the main() functionmust appear first, followed by subsequent functions.Some helpful hints are:• Create a block of code for one type of cookie. Test the code andcopy and modifythe block for the other 9 cookies.• As a helpful hint, after using cin >> to some variable, youwill need to clean out the newline character left in the buffer before doing a getline(cin,variable_name) by:cin.ignore();cin.clear();• Remember to do the cin.ignore() and cin.clear() before the nextgetline() and toopen the output file before your loop and close the file after yourloop.If you use the getline function, you can check the first characterof the string for "q" by:if (customer == "q")
==================================== Girl Scout Cookie Invoice ====================================Mon Jun 06 23:37:15 2022Johnny Good123 Main StreetBatavia, IL 60542Order Number: 1Dear Johnny B Good:Your Girl Scout Cookie order has arrived.Your order consists of the following:-------------------------------------------------| Cookie | Quantity | Cost |-------------------------------------------------| Thin Mints | 1 | $ 5.00 || Lemon-Up | 2 | $ 10.00 || Lemonades | 3 | $ 15.00 || Samoas | 4 | $ 20.00 || Tagalongs | 5 | $ 25.00 || Do-si-dos | 6 | $ 30.00 || Trefoils | 7 | $ 35.00 || Thanks-A-Lot | 8 | $ 40.00 || Toffee-tastic | 9 | $ 45.00 || Caramel Chocolate Chip | 10 | $ 50.00 |-------------------------------------------------| Total Due: | $ 275.00 |-------------------------------------------------
The program output should display exactly as shown.The fields have the following character lengths”• Cookie – 21 characters.• Quantity – 8 characters• Cost – 9 characters (1 for $, 8 for the money field with 2decimal points).• Each field begins with the | symbol followed by a space, then thefield data, then finally aspace and the | symbol.• The program can use the setw(n) to control the width of eachfield (remember to includethe header file iomanip).• All of the fields have a space before and after the field.The program should display the following heading before promptingthe user:"***********************************************""*** Welcome to Girl Scout Cookie Order Form ***""***********************************************""We promise to deliver excellent cookies to your doorstep."
In C++. the functions and loops are making me super confused when trying to use them together. Girl Scout Cookie Invoice
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am