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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
void placeOrder(fstream& afile, const char fileName[], fstream& afile2, const char fileName2[])
{
char custName[MAX];
char foodInfo[MAX];
int itemNo;
bool yes = true;
char yesno;
bool repeat = true;
static int orderNo = 1;
displayOrderMenu(afile2, "Menu.dat");
afile2.close();
afile.open(fileName, ios::out | ios::app | ios::binary); // transaction
afile2.open(fileName2, ios::in | ios:: out | ios::binary);
cout << "Please place your order\n" << endl;
custInfo ci;
adminInfo ai;
ci.total = 0;
cin.clear();
cin.ignore(MAX, '\n');
cout << "May i have your name?: ";
cin.getline(custName, MAX);
strcpy(ci.custName, custName);
cout << "Your table no: ";
cin >> ci.tableNo;
cout << endl;
int amount;
while(yes)
{
ci.orderNo = orderNo;
cin.clear();
cin.ignore(MAX, '\n');
cout << "Item No: ";
cin >> itemNo;
afile2.seekg((itemNo - 1) * sizeof(ai), ios::beg);
afile2.read(reinterpret_cast <char *>(&ai), sizeof (ai));
strcpy(ci.ai.foodName, ai.foodName);
cout << "How many: ";
cin >> ci.ai.amt;
cin.clear();
cin.ignore(MAX, '\n');
ai.amt = ai.amt - ci.ai.amt;
afile2.seekp ((itemNo - 1) * sizeof (ai), ios::beg);
afile2.write (reinterpret_cast<const char *>(&ai), sizeof(ai));
ci.ai.price = ai.price * ci.ai.amt;
ci.total = ci.ai.price + ci.total;
cout << "Any instructions: ";
cin.getline(foodInfo, MAX);
strcpy(ci.ai.foodInfo, foodInfo);
afile.write(reinterpret_cast <const char*>(&ci), sizeof (ci));
cout << "Any more items (Y/N) : " << yesno;
cin >> yesno;
cout << endl;
if(yesno == 'n')
{
yes = false;
}
else if (yesno == 'y')
{
yes = true;
yesno = NULL;
}
}
afile.close();
afile2.close();
|