Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6.  
  7. void login();
  8. void insertMovie();
  9. void viewAll();
  10. void bookTicket();
  11. float addon();
  12.  
  13. int main(void)
  14. {
  15.     int actionn;
  16.     login();
  17.  
  18.     do
  19.     {
  20.         printf("\n===================WELCOME TO 123 PANGGUNG=====================\n");
  21.         printf("\n Enter >1< To Insert Movie");
  22.         printf("\n Enter >2< To View All Movie");//
  23.         printf("\n Enter >3< To Book Tickets");//
  24.         printf("\n Enter >4< Log-out");
  25.         printf("\n Enter >5< Exit");
  26.  
  27.         printf("\n\nEnter action : ");
  28.         scanf("%d",&actionn);
  29.         system("cls");
  30.  
  31.         switch (actionn)
  32.         {
  33.             case 1:
  34.             insertMovie();
  35.             break;
  36.  
  37.             case 2:
  38.             viewAll();
  39.             break;
  40.  
  41.             case 3:
  42.             bookTicket();
  43.             break;
  44.  
  45.             case 4:
  46.             login();
  47.             break;
  48.  
  49.             case 5:
  50.             exit(0);
  51.             break;
  52.  
  53.             default:
  54.             printf("Wrong input !");
  55.             break;
  56.  
  57.         }
  58.  
  59.     }while (actionn!=0);
  60. }
  61.  
  62. void login()
  63. {
  64.     int a=0,i=0;
  65.     char uname[10],c=' ';
  66.     char pword[10],code[10];
  67.     char user[10]="zuriani";
  68.     char pass[10]="1234";
  69.  
  70.     do
  71.     {
  72.         printf("\n============================  WORKER LOGIN  ============================  ");
  73.         printf("\n\n ENTER USERNAME: ");
  74.         scanf("%s", &uname);
  75.         printf("\n ENTER PASSWORD: ");
  76.  
  77.         while(i<10)
  78.             {
  79.                 pword[i]=getch();
  80.                 c=pword[i];
  81.                 if(c==13) break;
  82.                 else printf("*");
  83.                 i++;
  84.             }
  85.  
  86.         pword[i]='\0';
  87.         i=0;
  88.  
  89.         if(strcmp(uname,"amin")==0 && strcmp(pword,"1234")==0)
  90.         {
  91.         printf("\n\n WELCOME TO 123 PANGGUNG, WORKER LOGIN IS SUCCESSFUL");
  92.         printf("\n\n Redirecting...");
  93.         Sleep(1500);
  94.         system("cls");
  95.         break;
  96.         }
  97.         else
  98.         {
  99.             printf("\n\nSORRY !!!!  LOGIN IS UNSUCESSFUL\n");
  100.             a++;
  101.             Sleep(1000);
  102.         }
  103.     }
  104.     while(a<=2);
  105.  
  106.     if (a>2)
  107.     {
  108.         printf("\n\a Sorry you have entered wrong username and password for three times!!! \n EXITING...\n");
  109.         Sleep(2000);
  110.         exit(1);
  111.     }
  112. }
  113.  
  114. void insertMovie()
  115. {
  116.     char code[3],moviename[20];
  117.     float cost;
  118.  
  119.     FILE *insert;
  120.  
  121.     printf("\n Enter movie code (XX) : ");
  122.     scanf("%s",&code);
  123.     fflush(stdin);
  124.     printf(" Enter movie name (Replace (-) for space) : ");
  125.     gets(moviename);
  126.     printf(" Enter ticket price : RM");
  127.     scanf("%f",&cost);
  128.  
  129.     insert=fopen("MovieList.txt","a");
  130.  
  131.     if(insert == NULL)
  132.     {
  133.         printf("\n\a FILE not found");
  134.         _getch();
  135.         exit(1);
  136.     }
  137.     else
  138.     {
  139.         fprintf(insert,"\n%s %s %.2f",code,moviename,cost);
  140.         printf("\n Successfully Recorded.\n Redirecting...");
  141.         Sleep(1500);
  142.     }
  143.     printf("\n");
  144.     fclose(insert);
  145.  
  146.     system("cls");
  147. }
  148.  
  149. void viewAll()
  150. {
  151.     char code1[3];
  152.     char movieName[100];
  153.     float cost;
  154.  
  155.     FILE *movie;
  156.  
  157.     movie = fopen("MovieList.txt","r");
  158.     if(movie == NULL)
  159.     {
  160.         printf("File does not found !");
  161.         _getch();
  162.         exit(1);
  163.     }
  164.     else
  165.     {
  166.         system("cls");
  167.         printf("\nList of all movies available :\n");
  168.         while( fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF )
  169.         {
  170.             printf("\n\t%s %s RM%.2f",code1,movieName,cost);
  171.         }
  172.         printf("\n");
  173.     }
  174.     fclose(movie);
  175.  
  176.     printf("\nPress enter to continue.");
  177.     _getch();
  178.     system("cls");
  179. }
  180.  
  181. void bookTicket()
  182. {
  183.     FILE *movie;
  184.     char code[3];
  185.     float cost,total_amount;
  186.     int total_seat;
  187.     char mobile[20];
  188.     char name[20];
  189.  
  190.     char ch; //used in display all movies
  191.     char code1[3];
  192.     char movieName[100];
  193.  
  194.     int success=0;
  195.     int caddon;
  196.     float totalAddon;
  197.  
  198.     movie = fopen("MovieList.txt","r");
  199.     if(movie == NULL)
  200.     {
  201.         printf("\a\nFile does found ! \nPress any key to exit.");
  202.         exit(1);
  203.     }
  204.     else
  205.     {
  206.         system("cls");
  207.         printf("\nList of all movies available :\n");
  208.         while( fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF )
  209.         {
  210.             printf("\n\t%s %s RM%.2f",code1,movieName,cost);
  211.         }
  212.         printf("\n");
  213.  
  214.     }
  215.     fclose(movie);
  216.  
  217.     printf("\n To book ticket, enter movie code(XX)\n");
  218.     do
  219.     {
  220.     printf("\n Enter movie code : ");
  221.     scanf("%s",&code);
  222.  
  223.     movie = fopen("MovieList.txt","r");
  224.  
  225.     if(movie == NULL)
  226.     {
  227.         printf("\a\nFile does found ! \nPress any key to exit.");
  228.         _getch;
  229.         exit(1);
  230.     }
  231.     else
  232.     {
  233.         while(fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF)
  234.         {
  235.             if(strcmp(code1, code) == 0)
  236.             {
  237.                 printf("\n Record Found\n");
  238.                 printf("\n\t\tMovie code      : %s",code1);
  239.                 printf("\n\t\tMovie name      : %s",movieName);
  240.                 printf("\n\t\tPrice of ticket : RM%.2f",cost);
  241.                 success=1;
  242.                 break;
  243.             }
  244.         }
  245.     }
  246.  
  247.     if (success==0)
  248.     {
  249.         printf("\n\a Entered wrong movie code. Try again\n");
  250.         Sleep(1000);
  251.     }
  252.     }while (success==0);
  253.  
  254.     printf("\n\n* Fill Customer Details *\n");
  255.     fflush(stdin);
  256.     printf("\n Customer name : ");
  257.     gets(name);
  258.     printf("\n Mobile number : ");
  259.     scanf("%s",&mobile);
  260.     printf("\n Total number of tickets : ");
  261.     scanf("%d",&total_seat);
  262.  
  263.  
  264.     total_amount = cost * total_seat;
  265.  
  266.     printf("\nDo customer want to buy addon? : ");
  267.     printf("\n 1 for YES");
  268.     printf("\n 2 for NO\n");
  269.     scanf("%d", &caddon);
  270.  
  271.     do
  272.     {
  273.         if (caddon == 1)
  274.         {
  275.             totalAddon = addon();
  276.             total_amount = total_amount + totalAddon;
  277.         }
  278.         else if (caddon > 2)
  279.         {
  280.             printf("\n\aEntered wrong input\n");
  281.         }
  282.  
  283.     }while (caddon > 2);
  284.  
  285.  
  286.  
  287.     system("cls");
  288.     FILE *output;
  289.  
  290.     output=fopen("Receipt.txt", "a");
  291.  
  292.     if(output == NULL)
  293.     {
  294.         printf("\a\nFile does found ! \nPress any key to exit.");
  295.         _getch;
  296.         exit(1);
  297.     }
  298.  
  299.     printf("\n------------------------------");
  300.     printf("\n      ENJOY YOUR MOVIE ");
  301.     printf("\n------------------------------");
  302.     printf("\n Name            : %s",name);
  303.     printf("\n Mobile Number   : %d",mobile);
  304.     printf("\n Movie name      : %s",movieName);
  305.     printf("\n Cost per ticket : RM%.2f",cost);
  306.     printf("\n Total seats     : %d",total_seat);
  307.     printf("\n Total Addons    : RM%.2f",totalAddon);
  308.     printf("\n Total Amount    : RM%.2f\n",total_amount);
  309.  
  310.     fprintf(output,"\nName            : %s",name);
  311.     fprintf(output,"\nMobile Number   : %d",mobile);
  312.     fprintf(output,"\nMovie name      : %s",movieName);
  313.     fprintf(output,"\nCost per ticket : RM%.2f",cost);
  314.     fprintf(output,"\nTotal seats     : %d",total_seat);
  315.     fprintf(output,"\nTotal Addons    : RM%.2f",totalAddon);
  316.     fprintf(output,"\nTotal Amount    : RM%.2f\n",total_amount);
  317.     fclose(output);
  318.  
  319.     printf("\n Press enter to continue");
  320.     _getch();
  321.     system("cls");
  322.  
  323. }
  324.  
  325. float addon()
  326. {
  327.     int addon;
  328.     int flavour;
  329.     char itemName[15][50];
  330.     float itemPrice[15];
  331.     int quantity;
  332.     float totalAddon = 0;
  333.  
  334.     printf("\n================================");
  335.     printf("\n            Add-on              ");
  336.     printf("\n================================");
  337.     printf("\n1. Popcorn - Vanilla/Strawberry/Chocolate");
  338.     printf("\n2. Drinks  - Milo/Coke/Coffee");
  339.     printf("\n3. Sausage\n");
  340.  
  341.     printf("\n How many addon to buy? : ");
  342.     scanf("%d", &quantity);
  343.  
  344.     for (int x=0; x < quantity;x++)
  345.     {
  346.         printf("\nChoose addon >%d< : ", x+1);
  347.         printf("\n1. Popcorn");
  348.         printf("\n2. Drinks");
  349.         printf("\n3. Sausage (RM3.00)\n");
  350.         scanf("%d", &addon);
  351.  
  352.         if (addon == 1)
  353.         {
  354.             printf("\nChoose popcorn flavour : ");
  355.             printf("\n1. Vanilla (RM 2.50)");
  356.             printf("\n2. Chocolate (RM 2.70)");
  357.             printf("\n3. Strawberry (RM 2.50)\n");
  358.             scanf("%d", &flavour);
  359.  
  360.             if (flavour == 1)
  361.             {
  362.                 strcpy(itemName[x], "Vanilla Popcorn");
  363.                 itemPrice[x] = 2.50;//
  364.             }
  365.             else if (flavour == 2)
  366.             {
  367.                 strcpy(itemName[x], "Chocolate Popcorn");
  368.                 itemPrice[x] = 2.70;//
  369.             }
  370.             else if (flavour == 3)
  371.             {
  372.                 strcpy(itemName[x], "Strawberry Popcorn");
  373.                 itemPrice[x] = 2.50;//
  374.             }
  375.             else
  376.             {
  377.                 strcpy(itemName[x], "INVALID ITEM");
  378.                 itemPrice[x] = 0;
  379.             }
  380.  
  381.         }
  382.         else if (addon == 2)
  383.         {
  384.             printf("\nChoose drinks : ");
  385.             printf("\n1. Milo (RM3.00)");
  386.             printf("\n2. Coke (RM3.00)");
  387.             printf("\n3. Coffee (RM2.00)\n");
  388.             scanf("%d", &flavour);
  389.  
  390.             if (flavour==1)
  391.             {
  392.                 strcpy(itemName[x], "Milo Ice");
  393.                 itemPrice[x] = 3.00;//
  394.             }
  395.  
  396.             else if (flavour==2)
  397.             {
  398.                 strcpy(itemName[x], "Coke Ice");
  399.                 itemPrice[x] = 3.00;//
  400.             }
  401.             else if (flavour==3)
  402.             {
  403.                 strcpy(itemName[x], "Hot Coffee");
  404.                 itemPrice[x] = 2.00;//
  405.             }
  406.             else
  407.             {
  408.                 strcpy(itemName[x], "INVALID ITEM");
  409.                 itemPrice[x] = 0;
  410.             }
  411.         }
  412.         else if (addon == 3)
  413.         {
  414.             strcpy(itemName[x], "Sausage");
  415.             itemPrice[x] = 3.00;//
  416.         }
  417.         else
  418.         {
  419.             strcpy(itemName[x], "INVALID ITEM");
  420.             itemPrice[x] = 0;
  421.         }
  422.  
  423.         totalAddon = totalAddon + itemPrice[x];
  424.     }
  425.  
  426.     printf("\nList of addons :");
  427.  
  428.     for (int x=0; x< quantity; x++)
  429.     {
  430.         printf("\n%d. %s (RM %.2f)", x+1, itemName[x], itemPrice[x]);
  431.     }
  432.  
  433.     printf("\n\nTotal addon : RM%.2f\n", totalAddon);
  434.     printf("\nPress enter to continue");
  435.     _getch();
  436.  
  437.     return totalAddon;
  438. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement