I have this C++ assignment and I had encountered several problems.For your information, I use Borland 5.02 software and this is my coding. The title is 'McDonalds'.
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
welcome();
while(15)
{
menu();
switch (set)
{
case 1:
set_1();
break;
case 2:
set_2();
break;
case 3:
set_3();
break;
case 4:
set_4();
break;
case 5:
exit();
break;
default:
cout<<"\n\t\tSorry, it's not a right input.."<<endl;
}
}
}
/*Main menu function
Users should choose from the menu displayed*/
void menu(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\n";
cout<<"\n\n\t\t\t\t MENU"<<endl; //display menu\\
cout<<"\n\t* Set 1: Bic Mac, Fries and soft drink - RM 5.88"<<endl;
cout<<"\n\t* Set 2: Double Cheese Burger, Fries and soft drink - RM7.30"<<endl;
cout<<"\n\t* Set 3: Quarter Pounder Burger, Fries and soft drink - RM8.40"<<endl;
cout<<"\n\t* Set 4: Beef Foldover, Fries and soft drink - RM9.70"<<endl;
cout<<"\n\n\t (1-Set 1, 2-Set 2, 3-Set 3, 4-Set4, 5-cancel)"<<endl;
cout<<"\n\t Please input you order: "; //input order\\
cin>>set;
}
//Welcome\\
void welcome (void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
//Functions for orders\\
//Set1\\
void set_1(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 1 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS1;
TPS1 = QS1*5.88;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 2 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS2;
TPS2 = QS2*7.30;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 3 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS3;
TPS3 = QS3*8.40;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 4 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS4;
TPS4 = QS4*9.70;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
//Function for calculation\\
//Total\\
void total(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
Tax = 0.5;
T = S + Tax;
cout<<"\n\n\n\tTotal sum is = RM "<<T;
cout<<"\n\n\n\tCash received = RM ";
cin>>CR;
B = CR - T;
cout<<"\n\n\tBalance is = RM "<<B<<endl;
exit();
getch();
}
//Exit program\\
void exit()
{
cout<<"\n\n\t\t\t\tThank You! "<<endl;
cout<<"\n\n\t\t\t Please come again!!"<<endl;
cout<<"\n\n\n\tPress any key to continue.... "<<endl;
getch();
}
The problems are:
1. I choose 'Yes' when I were asked if I want to add order. But when I input the order, I have to key in twice because the programs looks like it delays.
2. I was not able to lengthen the exit function because the program will just go through the 'Balance'.
3. Isn't the program should just exit after I press any key at the end??
I really hope anyone would help me.
Thank You and regards.
//Functions for orders\\
//Set1\\
void set_1(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 1 "<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS1;
TPS1 = QS1*5.88;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
//Set2\\
void set_2(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 2 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS2;
TPS2 = QS2*7.30;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
//Set3\\
void set_3(void)
{
clrscr();
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 3 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS3;
TPS3 = QS3*8.40;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\tYou ordered Set 4 ;]"<<endl;
cout<<"\n\t\tHow many set do you want? ";
cin>>QS4;
TPS4 = QS4*9.70;
cout<<"\n\n\tDo you want to add order? (Y-Yes, N-No) ";
cin>>add_order;