heryvandoro

Untitled

Mar 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<time.h>
  5. #include<malloc.h>
  6. //single linked list
  7.  
  8. struct food{
  9.     char name[100];
  10.     char type[100];
  11.     int price;
  12.     food *next;
  13. }*head=NULL,*tail=NULL,*curr=NULL;
  14.  
  15. void randomNum(){
  16.     srand(time(NULL));
  17.     int randomNum=rand()%10;
  18. }
  19.  
  20. void pushQue(char name[],char type[],int price){
  21.     struct food *curr=(struct food*)malloc(sizeof(food));
  22.     strcpy(curr->name,name);
  23.     strcpy(curr->type,type);
  24.     curr->price=price;
  25.  
  26.     if(head==NULL){
  27.         head=tail=curr;
  28.     }
  29.     else{
  30.         tail->next = curr;
  31.         tail = curr;
  32.     }
  33.     tail->next = NULL;
  34. }
  35.  
  36. void makeOrder(){
  37.     randomNum();
  38.     char order[100];
  39.     char orderID[100];
  40.     char yesorno[10];
  41.     char type[100];
  42.     int itemnumber=0;;
  43.     int price;
  44.     printf("Order ID: FD%d\n",randomNum);
  45.     printf("=======================\n");
  46.     do{
  47.         do{
  48.             printf("Input food name [Chicken Steak | Cheese Cake | Spiced Olives] :");
  49.             scanf("%[^\n]",&order);
  50.             fflush(stdin);
  51.  
  52.             if(strcmp(order,"Chicken Steak")==0){itemnumber=1;}
  53.             if(strcmp(order,"Cheese Cake")==0){itemnumber=2;}
  54.             if(strcmp(order,"Spiced Olives")==0){itemnumber=3;}
  55.    
  56.             if(itemnumber==1){
  57.                 strcpy(type,"Main Course");
  58.                 price=250000;
  59.             }
  60.  
  61.             if(itemnumber==2){
  62.                 strcpy(type,"Dessert");
  63.                 price=150000;
  64.             }
  65.  
  66.             if(itemnumber==3){
  67.                 strcpy(type,"Appetizer");
  68.                 price=100000;
  69.             }
  70.         }while(itemnumber==0);
  71.         pushQue(order,type,price);
  72.         printf("Do you want to add another food? [Y/N]: ");
  73.         scanf("%s",&yesorno);
  74.         fflush(stdin);
  75.     }while(strcmp(yesorno,"Y")==0);
  76. }
  77.  
  78. void viewOrder(){
  79.     randomNum();
  80.     if(head == NULL){
  81.         system("CLS");
  82.         printf("There's no Queue right now!\n");
  83.         getchar();
  84.     }
  85.     else{
  86.         struct food *curr=head;
  87.         while(curr!=NULL)
  88.         {
  89.             for(int i=1;i<3;i++)
  90.             {
  91.                 printf(" FD%d | %s | %s | %d\n",randomNum,curr->name,curr->type,curr->price);
  92.                 curr=curr->next;
  93.             }
  94.         }
  95.     }
  96. }
  97.  
  98.  
  99. void deleteOrder(){
  100.     if(head!=NULL)
  101.     {
  102.         curr=head;
  103.         head=head->next;
  104.         free(curr);
  105.     }
  106. }
  107.  
  108. int main(){
  109.    
  110.     int input=-1;
  111.     printf("Bluejack Restaurant Order\n");
  112.     printf("=========================\n");
  113.     printf("1. Make Order\n");
  114.     printf("2. View Order\n");
  115.     printf("3. Delete Order\n");
  116.     printf("4. Exit\n");
  117.    
  118.     printf("Input: ");
  119.     scanf("%d",&input);
  120.     fflush(stdin);
  121.     if(input==1){makeOrder();}
  122.     if(input==2){viewOrder();}
  123.     if(input==3){deleteOrder();}
  124.  
  125.     getchar();
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment