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

struct menuItemType
{
    char menuItem[15];
    double menuPrice;  
}
menuList[]= {"Plain Egg",2.50,
             "Bacon and Egg",3.45,
             "Muffin",2.20,
             "French Toast",2.95,
             "Fruit Basket",3.45,
             "Cereal",0.70,
             "Coffee",1.50,
             "Tea",1.80
             },order[10];
             
void getData(struct menuItemType[],struct menuItemType[],int*);
void showMenu(struct menuItemType[],int);
void printCheck(struct menuItemType[],int );

int main()
{
    int items = 0;

    printf("Welcome to HiFi's Restaurant\n");
    printf("\n");
    printf("******* MAIN MENU *******\n");
    printf("\n");
    printf("No.\tItem\t    Price\n");
    printf("-------------------------\n");
    showMenu(menuList,8);
    getData(menuList,order,&items);
    printCheck(order,items);
    getch();
    return 0;
}

void printCheck(struct menuItemType order[],int items)
{
     int i;
     double total = 0,tax;
     
     printf("\n****** Your Final Bill ******\n");
     printf("\n");
     printf("    Item\t    Price\n");
     printf("\n");
     showMenu(order,items);
     for(i=0;i<items;i++)
         total += order[i].menuPrice;
         printf("\nItem Total\t$%.2f\n",total);
         tax = total*0.05;
         printf("\nTax 5%%\t\t$%.2f\n",tax);
         printf("----------------------");
         printf("\nAmount Due\t$%.2f\n",total+tax);
         printf("----------------------");
}

void getData(struct menuItemType menu[],struct menuItemType order[],int* items)
{
    char response = 'Y',garbage;
    int n;
    
    while(response == 'Y'||response == 'y') {
        printf("Enter your order item number: ");
        scanf("%d",&n);
        
        while(n<1||n>8){
            printf("Invalid item number\n");
            printf("Enter your order item number: ");
            scanf("%d",&n);
            }
     //order[*items].menuItem=menu[n-1].menuItem;
     strcpy(order[*items].menuItem,menu[n-1].menuItem);
     order[*items].menuPrice = menu[n-1].menuPrice;
     *items = *items+1;
     scanf("%c",&garbage);
     printf("Would you like another item?(y/n)? ");
     scanf("%c",&response);
     }
}

void showMenu(struct menuItemType a[],int n)
{
     int i;
 
     for(i=0;i<n;i++)
     printf("%d   %-16s$%.2f\n",i+1,a[i].menuItem,a[i].menuPrice);
     printf("\n");
       
}

My problem is ... I want to display the output like this :
***** Your Final Bill *****
Item Price
1 Plain Egg $2.50
2 Bacon and Egg $7.90

instead of this one:

1 Plain Egg $2.50
2 Bacon and Egg $3.45
3 Bacon and Egg $3.45

can anyone help me to solve the problem?

You actually got this to compile with a C compiler? How did you manage that? Your structure and array of structures should be set up like below.

struct menuItemType
{
    char *menuItem;
    double menuPrice;  
};
struct menuItemType order[10] = 	
			{
				{"Plain Egg",2.50},
				{"Bacon and Egg",3.45},
				{"Muffin",2.20},
				{"French Toast",2.95},
				{"Fruit Basket",3.45},
				{"Cereal",0.70},
				{"Coffee",1.50},
				{"Tea",1.80}
			};

What I would recommend doing is changing the array order from an array of menuItemType to an array of integers that has an element for every item on the menu increment the array by 1 in the appropriate element of the array every time someone orders something.

That way for an order of 1 "plain egg" and 2 "bacon and egg" your array would look like 1,2,0,0...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.