There are some good ideas there, but it also seems muddled at times.
When the user is prompted for what they would like to order, the reading of the input file seems out-of sequence and unrelated in any way to what the user wants.
There are a lot of global variables. I would cut those down to the absolute minimum. For example there's no need for
char Another = ' ';
to be global. Make it a local variable declared inside the function
Logic()
which is the only place where it is used.
A suggestion.
Read from the file into an array (preferably a vector), to store the name and price of each item.
Use that array to later print out the menu, lookup the price of the item. Also use it to generate the receipt, you could print the name and quantity of each item as well as the cost.
It might be a good idea if the user could enter the number rather than the name of the item they want to order. It would make it possible to directly access the price from the array, whereas if they enter the name, it means having to search through the items one by one, hoping to find a match - assuming the user did not make any spelling mistakes and there's also the need to do a compare while ignoring the capitalisation which is extra effort.
An idea:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
struct Menuitem {
string name;
double price;
};
vector <Menuitem> menu;
void Welcome_Message()
{
cout << "\n\t\tHELLO AND WELCOME TO TI.LAUME PIZZERIA!\t\t\n";
cout << "\t\t========================================\t\t" << endl;
cout << "\n\t\tTHE PLACE WHERE ALL YOUR PIZZA DESIRES\t\t\n";
cout << "\t\tARE QUENCHED BY OUR DELICIOUS PIZZAS!\t\t" << endl;
cout << "\t\t========================================\t\t" << endl;
cout << endl << endl;
}
void LoadMenu()
{
ifstream read("store.txt");
Menuitem item = {"", 0};
// insert an empty item, so that numbering can start from 1, not zero.
menu.push_back(item);
while (getline(read, item.name, '#') && read >> item.price)
{
read.ignore(100, '\n'); // ignore till end of current line
menu.push_back(item);
}
}
void Menu()
{
cout << "\t~PIZZA MENU~\t" << endl;
cout << "########################" << endl;
for (size_t i = 1; i<menu.size(); ++i)
{
cout << " " << i << " "
<< left << setw(15) << menu[i].name
<< '$' << setw(2) << menu[i].price
<< '\n';
}
cout << "########################" << endl;
}
int main()
{
Welcome_Message() ;
LoadMenu();
Menu();
// Logic();
// Receipt();
}
|
Output:
HELLO AND WELCOME TO TI.LAUME PIZZERIA!
========================================
THE PLACE WHERE ALL YOUR PIZZA DESIRES
ARE QUENCHED BY OUR DELICIOUS PIZZAS!
========================================
~PIZZA MENU~
########################
1 CheeseBurger $5
2 DeluxeBurger $12
3 SmallPizza $7
4 MediumPizza $12
5 LargePizza $18
6 FamilyPizza $27
7 Coke $3
8 Sprite $3
9 Fanta $3
########################
|
Now, when the user chooses an item, say "DeluxeBurger", they could simply type the number '2' and the program can find the price as
menu[2].price
and the name as
menu[2].name
.