Hi Sir/Madam,

Need your help again, i failed to do output display for the menu list from this code. Suppose the output have to come out with menu = item selected, tax and amount of item.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>


double price[8] = {2.50 , 3.45, 2.20 , 2.95 , 3.45 , 0.70 , 1.50 , 1.80};
double mealTaxPrices[9];
int menuList,menuPrices;


void printMeals();
void orderMeals();
double order();

int main()
{
    char response = 'y';

     
     printMeals();
     while(response == 'y'|| response == 'Y')
    {          
            orderMeals();
            
            printf("\nwould you like to continue(y/n):");
            scanf(" %c",&response);
    }
  
 printf("\n      ******************** THANK YOU FOR COMING  *************************\n");
 printf("\20**********************   PLEASE VISIT US NEXT TIME  **************************\20 \n");
   system("pause");
   return 0;
}

void printMeals()
{
     
      printf(" \t\t\t WELCOME TO HiFi's RESTURANT  \n");
      printf(" \t\t\t \n");
      printf(" \t\t\t MEALS\t\t\tPRICE:\n");
      printf(" \t\t\t \22*******************************\22\n");
      printf(" \t\t\t 1- Plain Egg\t\t$2.50\n");
      printf(" \t\t\t 2- Bacon and Egg\t$3.45\n");
      printf(" \t\t\t 3- Muffin\t\t$2.20\n");
      printf(" \t\t\t 4- French Toast\t$2.95\n");
      printf(" \t\t\t 5- Fruit Basket\t$3.45\n");
      printf(" \t\t\t 6- Cereal\t\t$0.70\n");
      printf(" \t\t\t 7- Coffee\t\t$1.50\n");
      printf(" \t\t\t 8- Tea\t\t\t$1.80\n");
      printf("\n");
}
void orderMeals()
{
	double totalPrice;
	double allPayment;
//	double tax, taxAmount;
//	double menuList, totalAllManu;
         
         
     totalPrice =  order();
 //    tax= taxAmount;
 //    menuList = totalAllManu;
     allPayment =totalPrice;
     
     
 //    printf(" \t\t\tMenu List: \t\t\t%5.2f\n",menuList);
  //   printf(" \t\t\tTax:  5%% \t\t\t%5.2f\n",tax);
     printf(" \t\t\tTotal Amount: \t\t\t%5.2f\n",allPayment);


}
double order()
{
     int menuOption,i,amount;
      char response = 'y';
      double total = 0.0,totalAllMenu = 0.0;
      double tax = 5.0;

               while(response == 'y' || response == 'Y')
               {
                              printf("please choose your Meal(s):  ");
                              scanf("%d",&menuOption);
                              
                              printf("please enter your amount:");
                              scanf("%d",&amount);
                              
							  if(menuOption<1 || menuOption>7)
							  {
								  printf("sorry we don`t have this order \nagain! ");
								  continue;
							  }
							  
							  if (menuOption==1)
							  {
                                   printf("%d Plain Egg %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                           
                              	  
							  if (menuOption==2)
							  {
                                   printf("%d Bacon and Egg %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                              
                              
                              if (menuOption==3)
							  {
                                   printf("%d Muffin %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                              
                              if (menuOption==4)
							  {
                                   printf("%d French Toast %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }     
                              
                              
                              if (menuOption==5)
							  {
                                   printf("%d Fruit Basket %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                                   
                              if (menuOption==6)
							  {
                                   printf("%d Cereal %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                                   
                              if (menuOption==7)
							  {
                                   printf("%d Coffee %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }
                                   
                              if (menuOption==8)
							  {
                                   printf("%d Tea %8.2f",amount,(amount * price[menuOption - 1] ));
                                   }                
                              
                              total += (amount * price[menuOption - 1] );
                              
                              printf("\nWould you like to enter more orders(y/n):");
                              scanf(" %c",&response);
   
                              
                           
               }
               printf("\n");

               response = 'y';
     
     return total += total * tax / 100;
}

What are you expecting it to print? Can you narrow it down to a small section that's not working?

If I understand correctly you can't print tax because, in the function orderMeals(), the lines that print it are commented out. Even if it weren't it would not print anything because tax is initialized with taxAmount and taxAmount is not initialized with anything. Also the same for totalAllManu. Finally, tax and totalAllManu are calculated in the function order() and there is no way for them to get into the corresponding variables in orderMeals(). I suggest that you call order() and pass the address of tax and totalAllManu in orderMeals(). You must pass the addresses in order for the variables to get updated.

change order() to order(double *tax, double *totalAllManu)
change call to order to order(&tax, &totalAllManu)
remove variables tax and totalAllManu from order()
change references to tax and totalAllManu in order() to *tax and *totalAllMenu.
uncomment the lines

Do this and you will be OK to go.

Edited 5 Years Ago by jnawrocki: n/a

This article has been dead for over six months. Start a new discussion instead.