Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- struct menuItemType {
- string menuItem;
- double menuPrice;
- char selected;
- int quantity;
- };
- void getData(menuItemType menuList[]); //This function loads the data into the array menuList
- void showMenu(menuItemType menuList[]); //This function shows the different items offered by the restaurant and tells the user how to select the items.
- void printCheck(menuItemType menuList[]); //5% sales tax - Format your output with two decimal places. The name of each item in the output must be left justified.
- int main()
- {
- menuItemType menuList[8];
- getData(menuList);
- showMenu(menuList);
- return 0;
- }
- void getData(menuItemType menuList[])
- {
- ifstream infile;
- infile.open("9_4datafile.txt");
- for (int i = 0; i < 8; i++) {
- getline(infile, menuList[i].menuItem);
- infile >> menuList[i].menuPrice;
- menuList[i].selected = 'n';
- menuList[i].quantity = 0;
- infile.ignore();
- }
- infile.close();
- };
- void showMenu(menuItemType menuList[])
- {
- int count = 1;
- int itemNumber = 0;
- char selection;
- cout << "\n Welcome to Charlie Tuna's Resturant"
- << "\n----Today's Menu----"
- << endl;
- for (int i = 0; i < 8; i++) {
- cout << count++ << ". ";
- cout << menuList[i].menuItem << " "
- << fixed << setprecision(2) << "$" << menuList[i].menuPrice
- << endl;
- }
- cout << "\nYou can make up to 8 different selections."
- << "\nDo you want to make selection Y/y (Yes), N/n (No): ";
- cin >> selection;
- while (selection == 'y' || selection == 'Y') {
- cout << "\nEnter item number: ";
- cin >> itemNumber;
- menuList[itemNumber - 1].selected = 'y';
- cout << "\nHow many would you like to order?: ";
- cin >> menuList[itemNumber - 1].quantity;
- cout << "\nWould you like to make another selection: ";
- cin >> selection;
- }
- printCheck(menuList);
- cout << "\nThank you and have a nice day!";
- };
- void printCheck(menuItemType menuList[])
- {
- double grandTotal = 0;
- double rollingTotal = 0;
- for (int i = 0; i < 8; i++) {
- if (menuList[i].selected == 'y' || menuList[i].selected == 'Y') {
- rollingTotal += (menuList[i].menuPrice) * (menuList[i].quantity);
- grandTotal = rollingTotal + (rollingTotal * 0.05);
- cout << menuList[i].quantity << " " << menuList[i].menuItem << endl;
- }
- }
- cout << "\nYour total is: $" << fixed << setprecision(2) << grandTotal << endl;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement