A
Ashliey Elx
Hi, my program codes has no error but my mainMenu keeps on appearing at the end of every option I choose.
The last command of Food Menu is to ask user whether they want to add another food or not but when I key in Y/y, my mainMenu appear instead of my Food Menu, the same goes with my Drink Menu.
Anyone of you know what's wrong with my codes?
Header File:
void mainMenu();
void foodMenu();
void drinkMenu();
void totalPayment();
void exit();
Menu File:
#include "Header.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int option = 0;
char add;
const int SIZE = 20;
string foodCode;
string drinkCode;
int foodQty;
int drinkQty;
float foodPrice;
float drinkPrice;
float totalFood;
float totalDrink;
float totalPrice;
void mainMenu() {
int option=0;
do {
cout << endl
<< setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| ###### ###### ###### ##### |" << endl;
cout << setw(65) << "| # # # # |" << endl;
cout << setw(65) << "| ###### ###### # ### # |" << endl;
cout << setw(65) << "| # # # # # |" << endl;
cout << setw(65) << "| ###### ###### ###### ##### |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 1. Food Menu |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 2. Drink Menu |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 3. Total Payment |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 4. Exit |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl
<< endl;
cout << setw(45) << "Enter Your Option : ";
cin >> option;
cin.ignore(1,'\n');
cout << endl;
switch(option)
{
case 1:
foodMenu();
break;
case 2:
drinkMenu();
break;
case 3:
totalPayment();
break;
default:
cout << "Please enter a number between range 1-4!" << endl;
cout << "Enter Your option: ";
cin.ignore(1,'\n');
cin >> (option);
cin.ignore(1,'\n');
}
}while(option !=4);
}
void foodMenu() {
bool menu1 = true;
do {
char add;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| [ FOOD MENU ] |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| FOOD CODE PRICE |" << endl;
cout << setw(65) << "| F01 RICE RM1.00 |" << endl;
cout << setw(65) << "| F02 CURRY CHICKEN RM3.00 |" << endl;
cout << setw(65) << "| F03 FRIED CHICKEN RM3.00 |" << endl;
cout << setw(65) << "| F04 FRIED FISH RM2.00 |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(45) << "Enter Food Code : ";
cin >> foodCode;
cout << endl
<< setw(47) << "Enter Food Quantity : ";
cin >> foodQty;
cout << "Do you want to add another food[Y/N]: ";
cin >> add;
while (add != 'Y' && add != 'N' && add != 'y' && add != 'n'){
cout << "Please enter Y/N:";
cin >> add;
}
if (add == 'N' || add == 'n'){
mainMenu();
}
}while (add == 'Y' || add == 'y');
}
void drinkMenu() {
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| [ DRINK MENU ] |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| DRINK CODE PRICE |" << endl;
cout << setw(65) << "| D01 MILO RM1.80 |" << endl;
cout << setw(65) << "| D02 TEH-O RM0.90 |" << endl;
cout << setw(65) << "| D03 100 PLUS RM2.50 |" << endl;
cout << setw(65) << "| D04 APPLE JUICE RM2.00 |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(45) << "Enter Drink Code : ";
cin >> drinkCode;
cout << endl
<< setw(47) << "Enter Drink Quantity : ";
cin >> drinkQty;
}
void totalPayment() {
}
void exit () {
}
int main () {
mainMenu();
system("pause");
return 0;
}
The last command of Food Menu is to ask user whether they want to add another food or not but when I key in Y/y, my mainMenu appear instead of my Food Menu, the same goes with my Drink Menu.
Anyone of you know what's wrong with my codes?
Header File:
void mainMenu();
void foodMenu();
void drinkMenu();
void totalPayment();
void exit();
Menu File:
#include "Header.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int option = 0;
char add;
const int SIZE = 20;
string foodCode;
string drinkCode;
int foodQty;
int drinkQty;
float foodPrice;
float drinkPrice;
float totalFood;
float totalDrink;
float totalPrice;
void mainMenu() {
int option=0;
do {
cout << endl
<< setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| ###### ###### ###### ##### |" << endl;
cout << setw(65) << "| # # # # |" << endl;
cout << setw(65) << "| ###### ###### # ### # |" << endl;
cout << setw(65) << "| # # # # # |" << endl;
cout << setw(65) << "| ###### ###### ###### ##### |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 1. Food Menu |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 2. Drink Menu |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 3. Total Payment |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| 4. Exit |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl
<< endl;
cout << setw(45) << "Enter Your Option : ";
cin >> option;
cin.ignore(1,'\n');
cout << endl;
switch(option)
{
case 1:
foodMenu();
break;
case 2:
drinkMenu();
break;
case 3:
totalPayment();
break;
default:
cout << "Please enter a number between range 1-4!" << endl;
cout << "Enter Your option: ";
cin.ignore(1,'\n');
cin >> (option);
cin.ignore(1,'\n');
}
}while(option !=4);
}
void foodMenu() {
bool menu1 = true;
do {
char add;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| [ FOOD MENU ] |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| FOOD CODE PRICE |" << endl;
cout << setw(65) << "| F01 RICE RM1.00 |" << endl;
cout << setw(65) << "| F02 CURRY CHICKEN RM3.00 |" << endl;
cout << setw(65) << "| F03 FRIED CHICKEN RM3.00 |" << endl;
cout << setw(65) << "| F04 FRIED FISH RM2.00 |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(45) << "Enter Food Code : ";
cin >> foodCode;
cout << endl
<< setw(47) << "Enter Food Quantity : ";
cin >> foodQty;
cout << "Do you want to add another food[Y/N]: ";
cin >> add;
while (add != 'Y' && add != 'N' && add != 'y' && add != 'n'){
cout << "Please enter Y/N:";
cin >> add;
}
if (add == 'N' || add == 'n'){
mainMenu();
}
}while (add == 'Y' || add == 'y');
}
void drinkMenu() {
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "| SEGi College Canteen System |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| [ DRINK MENU ] |" << endl;
cout << setw(65) << "| |" << endl;
cout << setw(65) << "| DRINK CODE PRICE |" << endl;
cout << setw(65) << "| D01 MILO RM1.80 |" << endl;
cout << setw(65) << "| D02 TEH-O RM0.90 |" << endl;
cout << setw(65) << "| D03 100 PLUS RM2.50 |" << endl;
cout << setw(65) << "| D04 APPLE JUICE RM2.00 |" << endl;
cout << setw(65) << "* *" << endl;
cout << setw(65) << "* * - - - - - - - - - - - - - - - - - - - - - - - * *" << endl;
cout << setw(45) << "Enter Drink Code : ";
cin >> drinkCode;
cout << endl
<< setw(47) << "Enter Drink Quantity : ";
cin >> drinkQty;
}
void totalPayment() {
}
void exit () {
}
int main () {
mainMenu();
system("pause");
return 0;
}