Hi guys I need your help. Basically this is a restaurant ordering program where a customer can ordering multiple kinds food in one order/transaction.
For example, i will input:
Table Number: 1
Priority Number: 1
How many kinds of food to order?: 2
Order 1: chicken
Quantity: 2
Order 2: salad
Quantity: 1
I am actually hoping that the program will output:
Code:
Table 1, Priority 0,
Order: chicken , Quantity: 2
Order: salad , Quantity: 1
But instead, it will just output:
Code:
Table 1, Priority 0,
Order: (null), Quantity: 2
So, here is the code:
Code:
#include<stdio.h>#include<stdlib.h>
#include<string.h>
typedef struct orders
{
int *quantity[50];
char *foodname[50];
}ORDER;
typedef struct Table
{
int tableno;
int priority;
ORDER *orders;
struct Table *next;
}TABLE;
TABLE *head, *s;
int n=0;
int insert(int tablenum, int prio, int kindsoforder, char *foodname[50], int qty[50])
{
int l;
TABLE *newO, *temp;
newO = (TABLE *)malloc(sizeof(TABLE));
newO->tableno = tablenum;
newO->priority = prio;
for(l=0;l<kindsoforder;l++)
{
strcpy(newO->orders->foodname[l], foodname[l]);
newO->orders->quantity[l] = qty[l];
}
if(head == NULL)
{
head = newO;
newO->next = NULL;
}
else
{
temp = head;
newO->next = temp;
while(temp->next != NULL)
{
if(newO->priority > head->priority)
{
head->next = newO;
newO->next = temp->next;
}
else
{
newO->next = head->next;
head->next = newO;
}
temp = temp->next;
}
}
n++;
printf("\nTotal numbers of orders for today: %d", n);
return 1;
}
void showlist()
{
int i, k;
s=head;
for(i=0;i<n;i++)
{
printf("\nTable No: %d, Priority: %d, \n",s->tableno, i);
for(k=0;k<n;k++)
{
printf("Order: %s, Quantity: %d \n", s->orders->foodname[k],s->orders->quantity[k]);
}
s=s->next;
}
printf("\n");
}
void main()
{
int tablenum, prio, *qty[50], a, kindsoforder,j;
char choice, *foodname[50];
clrscr();
while(choice != 'b')
{
flushall();
printf("a. Order\nb. Exit\n");
scanf("%c", &choice);
switch(choice)
{
case 'a':
printf("Table Number: \n");
scanf("%d", &tablenum);
printf("Priority Number: \n");
scanf("%d", &prio);
printf("How many kinds of order? \n");
scanf("%d", &kindsoforder);
if(kindsoforder == 0)
{
break;
}
else
{
for(j=0;j<=kindsoforder;j++)
{
printf("Order %d: \n", j+1);
scanf("%s", &foodname[j]);
printf("Quantity? \n");
scanf("%d", &qty[j]);
}
}
a = insert(tablenum, prio, kindsoforder, foodname, qty);
if (a == 1)
{
printf("\nOrder inserted!\n\n");
showlist();
}
else
{
printf("Order not inserted!\n");
}
break;
case 'b':
printf("Exit!");
break;
}
}
getch();
}
Please help me.