I need HELP! McD program!

Apr 5, 2008 at 10:07pm
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'.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>

//Variables declaration and functions\\
void set_1 (void);
void set_2(void);
void set_3(void);
void set_4(void);
void welcome(void);
void menu(void);
void exit (void);
void total(void);

int set, QS1, QS2, QS3, QS4;
float TPS1, TPS2, TPS3, TPS4, S, Tax, T, CR, B;
char add_order, where;

//Time declaration\\
time_t masa;

void main()
{

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);

cout<<"\n\n";
cout<<"\n\n\n\n\t\t ---------------------------"<<endl; //display welcome\\
cout<<"\t\t ---------------------------"<<endl;
cout<<"\n\t\t\t(=Welcome to McDonald=)"<<endl;
cout<<"\n\t\t\t 'I'm lovin' it'\n"<<endl;
cout<<"\t\t ---------------------------"<<endl;
cout<<"\t\t ---------------------------"<<endl;
getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//Set4\\
void set_4(void)
{
clrscr();

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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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.

May 18, 2008 at 3:26am
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>

//Variables declaration and functions\\
void set_1 (void);
void set_2(void);
void set_3(void);
void set_4(void);
void welcome(void);
void menu(void);
void exit (void);
void total(void);

int set, QS1, QS2, QS3, QS4;
float TPS1, TPS2, TPS3, TPS4, S, Tax, T, CR, B;
char add_order,a;

//Time declaration\\
time_t masa;

void main()
{
time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);

welcome();
while(10)
{
menu();
}
}

/*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;
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;
}
}

//Welcome\\
void welcome (void)
{
clrscr();

time (&masa);
cout<<"\n\n\t\t\t\t\t\t"<<ctime (&masa);
cout<<"\n\n";
cout<<"\n\n\n\n\t\t ---------------------------"<<endl; //display welcome\\
cout<<"\t\t ---------------------------"<<endl;
cout<<"\n\t\t\t(=Welcome to McDonald=)"<<endl;
cout<<"\n\t\t\t 'I'm lovin' it'\n"<<endl;
cout<<"\t\t ---------------------------"<<endl;
cout<<"\t\t ---------------------------"<<endl;
getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//Set4\\
void set_4(void)
{
clrscr();

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;

if((add_order =='Y')||(add_order == 'y'))
menu();
else
{
S = TPS1+TPS2+TPS3+TPS4;
total();
}

getch();
}

//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\t Press 'c' to continue...and press 'e' to exit....... "<<endl;
cin>>a;

if(a=='c'|| a=='C')
menu();
else if(a=='e' || a=='E')
exit(0);
}


Topic archived. No new replies allowed.