Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <windows.h>
- void login();
- void insertMovie();
- void viewAll();
- void bookTicket();
- float addon();
- int main(void)
- {
- int actionn;
- login();
- do
- {
- printf("\n===================WELCOME TO 123 PANGGUNG=====================\n");
- printf("\n Enter >1< To Insert Movie");
- printf("\n Enter >2< To View All Movie");//
- printf("\n Enter >3< To Book Tickets");//
- printf("\n Enter >4< Log-out");
- printf("\n Enter >5< Exit");
- printf("\n\nEnter action : ");
- scanf("%d",&actionn);
- system("cls");
- switch (actionn)
- {
- case 1:
- insertMovie();
- break;
- case 2:
- viewAll();
- break;
- case 3:
- bookTicket();
- break;
- case 4:
- login();
- break;
- case 5:
- exit(0);
- break;
- default:
- printf("Wrong input !");
- break;
- }
- }while (actionn!=0);
- }
- void login()
- {
- int a=0,i=0;
- char uname[10],c=' ';
- char pword[10],code[10];
- char user[10]="zuriani";
- char pass[10]="1234";
- do
- {
- printf("\n============================ WORKER LOGIN ============================ ");
- printf("\n\n ENTER USERNAME: ");
- scanf("%s", &uname);
- printf("\n ENTER PASSWORD: ");
- while(i<10)
- {
- pword[i]=getch();
- c=pword[i];
- if(c==13) break;
- else printf("*");
- i++;
- }
- pword[i]='\0';
- i=0;
- if(strcmp(uname,"amin")==0 && strcmp(pword,"1234")==0)
- {
- printf("\n\n WELCOME TO 123 PANGGUNG, WORKER LOGIN IS SUCCESSFUL");
- printf("\n\n Redirecting...");
- Sleep(1500);
- system("cls");
- break;
- }
- else
- {
- printf("\n\nSORRY !!!! LOGIN IS UNSUCESSFUL\n");
- a++;
- Sleep(1000);
- }
- }
- while(a<=2);
- if (a>2)
- {
- printf("\n\a Sorry you have entered wrong username and password for three times!!! \n EXITING...\n");
- Sleep(2000);
- exit(1);
- }
- }
- void insertMovie()
- {
- char code[3],moviename[20];
- float cost;
- FILE *insert;
- printf("\n Enter movie code (XX) : ");
- scanf("%s",&code);
- fflush(stdin);
- printf(" Enter movie name (Replace (-) for space) : ");
- gets(moviename);
- printf(" Enter ticket price : RM");
- scanf("%f",&cost);
- insert=fopen("MovieList.txt","a");
- if(insert == NULL)
- {
- printf("\n\a FILE not found");
- _getch();
- exit(1);
- }
- else
- {
- fprintf(insert,"\n%s %s %.2f",code,moviename,cost);
- printf("\n Successfully Recorded.\n Redirecting...");
- Sleep(1500);
- }
- printf("\n");
- fclose(insert);
- system("cls");
- }
- void viewAll()
- {
- char code1[3];
- char movieName[100];
- float cost;
- FILE *movie;
- movie = fopen("MovieList.txt","r");
- if(movie == NULL)
- {
- printf("File does not found !");
- _getch();
- exit(1);
- }
- else
- {
- system("cls");
- printf("\nList of all movies available :\n");
- while( fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF )
- {
- printf("\n\t%s %s RM%.2f",code1,movieName,cost);
- }
- printf("\n");
- }
- fclose(movie);
- printf("\nPress enter to continue.");
- _getch();
- system("cls");
- }
- void bookTicket()
- {
- FILE *movie;
- char code[3];
- float cost,total_amount;
- int total_seat;
- char mobile[20];
- char name[20];
- char ch; //used in display all movies
- char code1[3];
- char movieName[100];
- int success=0;
- int caddon;
- float totalAddon;
- movie = fopen("MovieList.txt","r");
- if(movie == NULL)
- {
- printf("\a\nFile does found ! \nPress any key to exit.");
- exit(1);
- }
- else
- {
- system("cls");
- printf("\nList of all movies available :\n");
- while( fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF )
- {
- printf("\n\t%s %s RM%.2f",code1,movieName,cost);
- }
- printf("\n");
- }
- fclose(movie);
- printf("\n To book ticket, enter movie code(XX)\n");
- do
- {
- printf("\n Enter movie code : ");
- scanf("%s",&code);
- movie = fopen("MovieList.txt","r");
- if(movie == NULL)
- {
- printf("\a\nFile does found ! \nPress any key to exit.");
- _getch;
- exit(1);
- }
- else
- {
- while(fscanf(movie,"%s %s %f",&code1,&movieName,&cost) != EOF)
- {
- if(strcmp(code1, code) == 0)
- {
- printf("\n Record Found\n");
- printf("\n\t\tMovie code : %s",code1);
- printf("\n\t\tMovie name : %s",movieName);
- printf("\n\t\tPrice of ticket : RM%.2f",cost);
- success=1;
- break;
- }
- }
- }
- if (success==0)
- {
- printf("\n\a Entered wrong movie code. Try again\n");
- Sleep(1000);
- }
- }while (success==0);
- printf("\n\n* Fill Customer Details *\n");
- fflush(stdin);
- printf("\n Customer name : ");
- gets(name);
- printf("\n Mobile number : ");
- scanf("%s",&mobile);
- printf("\n Total number of tickets : ");
- scanf("%d",&total_seat);
- total_amount = cost * total_seat;
- printf("\nDo customer want to buy addon? : ");
- printf("\n 1 for YES");
- printf("\n 2 for NO\n");
- scanf("%d", &caddon);
- do
- {
- if (caddon == 1)
- {
- totalAddon = addon();
- total_amount = total_amount + totalAddon;
- }
- else if (caddon > 2)
- {
- printf("\n\aEntered wrong input\n");
- }
- }while (caddon > 2);
- system("cls");
- FILE *output;
- output=fopen("Receipt.txt", "a");
- if(output == NULL)
- {
- printf("\a\nFile does found ! \nPress any key to exit.");
- _getch;
- exit(1);
- }
- printf("\n------------------------------");
- printf("\n ENJOY YOUR MOVIE ");
- printf("\n------------------------------");
- printf("\n Name : %s",name);
- printf("\n Mobile Number : %d",mobile);
- printf("\n Movie name : %s",movieName);
- printf("\n Cost per ticket : RM%.2f",cost);
- printf("\n Total seats : %d",total_seat);
- printf("\n Total Addons : RM%.2f",totalAddon);
- printf("\n Total Amount : RM%.2f\n",total_amount);
- fprintf(output,"\nName : %s",name);
- fprintf(output,"\nMobile Number : %d",mobile);
- fprintf(output,"\nMovie name : %s",movieName);
- fprintf(output,"\nCost per ticket : RM%.2f",cost);
- fprintf(output,"\nTotal seats : %d",total_seat);
- fprintf(output,"\nTotal Addons : RM%.2f",totalAddon);
- fprintf(output,"\nTotal Amount : RM%.2f\n",total_amount);
- fclose(output);
- printf("\n Press enter to continue");
- _getch();
- system("cls");
- }
- float addon()
- {
- int addon;
- int flavour;
- char itemName[15][50];
- float itemPrice[15];
- int quantity;
- float totalAddon = 0;
- printf("\n================================");
- printf("\n Add-on ");
- printf("\n================================");
- printf("\n1. Popcorn - Vanilla/Strawberry/Chocolate");
- printf("\n2. Drinks - Milo/Coke/Coffee");
- printf("\n3. Sausage\n");
- printf("\n How many addon to buy? : ");
- scanf("%d", &quantity);
- for (int x=0; x < quantity;x++)
- {
- printf("\nChoose addon >%d< : ", x+1);
- printf("\n1. Popcorn");
- printf("\n2. Drinks");
- printf("\n3. Sausage (RM3.00)\n");
- scanf("%d", &addon);
- if (addon == 1)
- {
- printf("\nChoose popcorn flavour : ");
- printf("\n1. Vanilla (RM 2.50)");
- printf("\n2. Chocolate (RM 2.70)");
- printf("\n3. Strawberry (RM 2.50)\n");
- scanf("%d", &flavour);
- if (flavour == 1)
- {
- strcpy(itemName[x], "Vanilla Popcorn");
- itemPrice[x] = 2.50;//
- }
- else if (flavour == 2)
- {
- strcpy(itemName[x], "Chocolate Popcorn");
- itemPrice[x] = 2.70;//
- }
- else if (flavour == 3)
- {
- strcpy(itemName[x], "Strawberry Popcorn");
- itemPrice[x] = 2.50;//
- }
- else
- {
- strcpy(itemName[x], "INVALID ITEM");
- itemPrice[x] = 0;
- }
- }
- else if (addon == 2)
- {
- printf("\nChoose drinks : ");
- printf("\n1. Milo (RM3.00)");
- printf("\n2. Coke (RM3.00)");
- printf("\n3. Coffee (RM2.00)\n");
- scanf("%d", &flavour);
- if (flavour==1)
- {
- strcpy(itemName[x], "Milo Ice");
- itemPrice[x] = 3.00;//
- }
- else if (flavour==2)
- {
- strcpy(itemName[x], "Coke Ice");
- itemPrice[x] = 3.00;//
- }
- else if (flavour==3)
- {
- strcpy(itemName[x], "Hot Coffee");
- itemPrice[x] = 2.00;//
- }
- else
- {
- strcpy(itemName[x], "INVALID ITEM");
- itemPrice[x] = 0;
- }
- }
- else if (addon == 3)
- {
- strcpy(itemName[x], "Sausage");
- itemPrice[x] = 3.00;//
- }
- else
- {
- strcpy(itemName[x], "INVALID ITEM");
- itemPrice[x] = 0;
- }
- totalAddon = totalAddon + itemPrice[x];
- }
- printf("\nList of addons :");
- for (int x=0; x< quantity; x++)
- {
- printf("\n%d. %s (RM %.2f)", x+1, itemName[x], itemPrice[x]);
- }
- printf("\n\nTotal addon : RM%.2f\n", totalAddon);
- printf("\nPress enter to continue");
- _getch();
- return totalAddon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement