Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///CODED BY AARGH(cplusplus.com)
- ///http://www.cplusplus.com/forum/beginner/75558/
- #include <iostream>
- #include <string>
- using namespace std;
- struct menuItemType
- {
- string name;
- double price;
- };
- void GetData(menuItemType & menu, string name, double price)
- {
- menu.name = name;
- menu.price = price;
- }
- void ShowMenu()
- {
- cout << "(1) Plain Egg.............1.45\n"
- << "(2) Bacon and Egg....2.45\n"
- << "(3) Muffin..................0.99\n"
- << "(4) French Toast.......1.99\n"
- << "(5) Fruit Basket.........2.49\n"
- << "(6) Cereal.................0.50\n"
- << "(7) Tea......................0.75\n";
- }
- void printCheck(menuItemType& selection, double* total)
- {
- *total += selection.price;
- cout << selection.name << " " << selection.price << endl;
- }
- int main()
- {
- menuItemType menuList[50];
- cout << "Select up to 50 items by their menu numbers. Press s then enter key to stop\n";
- int choice;
- int counter = 0; // used to ensure array does not run out of bounds
- double price; // price for each menu item added to the array
- double total = 0; // running total
- string name; // name for each menu item added to the array
- menuItemType * ptr_begin(menuList); // pointers will be used to manual figure out the size of the array (how many elements have valid values in them)
- menuItemType * ptr_end(menuList); // end pointer will iterate down the array to mark where the end would be
- ShowMenu();
- while (cin >> choice)
- {
- ShowMenu();
- if (choice == 1)
- {
- price = 1.45;
- name = "Plain Egg";
- }
- else if (choice == 2)
- {
- price = 2.45;
- name = "Bacon and Egg";
- }
- else if (choice == 3)
- {
- price = 0.99;
- name = "Muffin";
- }
- else if (choice == 4)
- {
- price = 1.99;
- name = "French Toast";
- }
- else if (choice == 5)
- {
- price = 2.49;
- name = "Fruit Basket";
- }
- else if (choice == 6)
- {
- price = 0.50;
- name = "Cereal";
- }
- else if (choice == 7)
- {
- price = 0.75;
- name = "Tea";
- }
- else // if user entered an improper selection number.
- {
- cout << "\n***Thats not a proper selection. Please try again.***\n";
- continue;
- }
- GetData(menuList[counter], name, price);
- ptr_end += 1;
- ++counter;
- if (counter == 50) // user entered maximum selection of menu items.
- break;
- }
- if (ptr_begin != ptr_end) // if pointers point to different areas of array then we know user chose something to order and will display the bill.
- {
- cout << "\nYou selection consists of;\n";
- for (menuItemType * ptr_begin(menuList); ptr_begin != ptr_end; ptr_begin += 1)
- {
- printCheck(*ptr_begin, &total);
- }
- cout << "\nYour total bill including 5% tax will be: $";
- cout.precision(3);
- cout << total * 1.05 << endl;
- }
- cout << "\nThank you. Come again.\n";
- char f; // use to prevent console from closing down. may not work on MS visual C++ compiler for some reason.
- cin >> f;
- //system("pause"); //use for MS visual C++ to prevent console from closing down too fast.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement