Author Topic: Full documented a restaurant menu program  (Read 3018 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Full documented a restaurant menu program
« on: November 10, 2011, 08:14:15 pm »
Write a full documented a restaurant menu program that asks the user questions and the user should answer with Y or N. With each question the program will calculate his bill

The Output is as the following:
The Menu is
Salad: 0.45
Pepsi: 0.35
Falafel: 0.75
Shawerma: 1.25
Potato: 0.50

Do you want Salad : Y
Do you want Pepsi : N
Do you want Falafel : R
Do you want Shawerma :Y
Do you want Potato :Y
Your Bill is : 0.45 + 1.25 + 0.50 = 2.20


Code:
//Source Code Listing

#include <stdio.h>
#include <conio.h>
#include <malloc.h>

typedef struct _menuitem
{
   char item[64];
   double price;
} menuitem;

menuitem item1 = { "Salad", 0.45 };
menuitem item2 = { "Pepsi", 0.35 };
menuitem item3 = { "Falafel", 0.75 };
menuitem item4 = { "Shawerma", 1.25 };
menuitem item5 = { "Potato", 0.50 };

menuitem *menuitem_list[] = {
   &item1, &item2, &item3, &item4, &item5
};

void main()
{
   int i, firstitem = 1;
   char resp[24];
   double price = 0;
   int numitems = sizeof(menuitem_list) / sizeof(menuitem_list[0]);
   
   for(i = 0; i < numitems; i++)
   {
      printf("%12s\t:  %.2lf\n", menuitem_list[i]->item, menuitem_list[i]->price);
   }

   for(i = 0; i < numitems; i++)
   {
      printf("\nDo you want %s? ", menuitem_list[i]->item);
      resp[i] = _getche();
   }

   printf("\n\nYour bill is: ");
   for(i = 0; i < numitems; i++)
   {
      if(resp[i] == 'Y' || resp[i] == 'y')
      {
         price += menuitem_list[i]->price;
         if(firstitem == 1)
            firstitem = 0;
         else
            printf(" + ");
         printf("%.2lf", menuitem_list[i]->price);
         
      }
   }
   printf(" =  %.2lf\n\n", price);
}

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1