Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<time.h>
- #include<malloc.h>
- //single linked list
- struct food{
- char name[100];
- char type[100];
- int price;
- food *next;
- }*head=NULL,*tail=NULL,*curr=NULL;
- void randomNum(){
- srand(time(NULL));
- int randomNum=rand()%10;
- }
- void pushQue(char name[],char type[],int price){
- struct food *curr=(struct food*)malloc(sizeof(food));
- strcpy(curr->name,name);
- strcpy(curr->type,type);
- curr->price=price;
- if(head==NULL){
- head=tail=curr;
- }
- else{
- tail->next = curr;
- tail = curr;
- }
- tail->next = NULL;
- }
- void makeOrder(){
- randomNum();
- char order[100];
- char orderID[100];
- char yesorno[10];
- char type[100];
- int itemnumber=0;;
- int price;
- printf("Order ID: FD%d\n",randomNum);
- printf("=======================\n");
- do{
- do{
- printf("Input food name [Chicken Steak | Cheese Cake | Spiced Olives] :");
- scanf("%[^\n]",&order);
- fflush(stdin);
- if(strcmp(order,"Chicken Steak")==0){itemnumber=1;}
- if(strcmp(order,"Cheese Cake")==0){itemnumber=2;}
- if(strcmp(order,"Spiced Olives")==0){itemnumber=3;}
- if(itemnumber==1){
- strcpy(type,"Main Course");
- price=250000;
- }
- if(itemnumber==2){
- strcpy(type,"Dessert");
- price=150000;
- }
- if(itemnumber==3){
- strcpy(type,"Appetizer");
- price=100000;
- }
- }while(itemnumber==0);
- pushQue(order,type,price);
- printf("Do you want to add another food? [Y/N]: ");
- scanf("%s",&yesorno);
- fflush(stdin);
- }while(strcmp(yesorno,"Y")==0);
- }
- void viewOrder(){
- randomNum();
- if(head == NULL){
- system("CLS");
- printf("There's no Queue right now!\n");
- getchar();
- }
- else{
- struct food *curr=head;
- while(curr!=NULL)
- {
- for(int i=1;i<3;i++)
- {
- printf(" FD%d | %s | %s | %d\n",randomNum,curr->name,curr->type,curr->price);
- curr=curr->next;
- }
- }
- }
- }
- void deleteOrder(){
- if(head!=NULL)
- {
- curr=head;
- head=head->next;
- free(curr);
- }
- }
- int main(){
- int input=-1;
- printf("Bluejack Restaurant Order\n");
- printf("=========================\n");
- printf("1. Make Order\n");
- printf("2. View Order\n");
- printf("3. Delete Order\n");
- printf("4. Exit\n");
- printf("Input: ");
- scanf("%d",&input);
- fflush(stdin);
- if(input==1){makeOrder();}
- if(input==2){viewOrder();}
- if(input==3){deleteOrder();}
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment