Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- struct dates
- {
- int dateloopd,dayd,monthd;
- };
- struct receipts
- {
- int start,desti,seating,arrivaltime,dayr,monthr,train,time;
- float fee;
- };
- int menu(void);
- int startf();
- int destif(int start);
- int confirmation(int start, int desti);
- struct dates datef();
- int timef();
- int trainf();
- int seatingf();
- int agediscountf();
- int discountf();
- int timecf(int start, int desti, int time, int traintype);
- float feef(int start, int desti,int seattype, int traintype, float agediscmod, float discmod, struct dates display);
- void receiptf(int start, int desti, struct dates display, int time, int train, int seating, int arrivaltime, float fee);
- void receiptoutf(struct receipts receiptout);
- int main()
- {
- int menuloop=0, start,desti,startloop,destiloop,dateloop,date,timeloop,time,trainloop,train,traintype,discloop,agediscloop,agedisc,seating,seatloop,seattype,discount,receiptloop,confirm;
- int arrivaltime;
- float agediscmod,discmod,fee;
- struct dates display;
- struct receipts receiptout;
- do
- {
- menuloop = menu();
- switch (menuloop)
- {
- case 1:
- startloop = 1;
- break;
- default:
- startloop = 0;
- break;
- }
- while (startloop == 1)
- {
- start = startf();
- switch (start)
- {
- case 1: case 2: case 3:
- destiloop = 1;
- break;
- case 0:
- startloop = 0;
- destiloop = 0;
- break;
- default:
- destiloop = 0;
- break;
- }
- while (destiloop == 1)
- {
- desti = destif(start);
- switch (desti)
- {
- case 1: case 2: case 3:
- confirm = confirmation(start,desti);
- break;
- case 9 :
- confirm = 2;
- break;
- default:
- confirm = 2;
- break;
- }
- switch (confirm)
- {
- case 1:
- dateloop = 1;
- destiloop = 0;
- break;
- case 2:
- dateloop = 0;
- destiloop = 0;
- startloop = 1;
- break;
- case 3:
- dateloop = 0;
- destiloop = 1;
- break;
- default:
- destiloop = 1;
- dateloop = 0;
- break;
- }
- while (dateloop == 1)
- {
- display = datef();
- date = display.dateloopd;
- switch (date)
- {
- case 1:
- dateloop = 0;
- timeloop = 1;
- break;
- case 0:
- dateloop = 1;
- timeloop = 0;
- break;
- default:
- dateloop = 1;
- timeloop = 0;
- break;
- }
- while (timeloop == 1)
- {
- system("CLS");
- time = timef();
- switch (time)
- {
- case 1000:
- timeloop = 0;
- trainloop = 1;
- break;
- case 1200:
- timeloop = 0;
- trainloop = 1;
- break;
- case 9:
- dateloop = 1;
- timeloop = 0;
- trainloop = 0;
- break;
- default:
- timeloop = 1;
- trainloop = 0;
- break;
- }
- while (trainloop == 1)
- {
- train = trainf();
- switch (train)
- {
- case 1:
- traintype = 1;
- trainloop = 0;
- seatloop = 1;
- break;
- case 2:
- traintype = 2;
- trainloop = 0;
- seatloop = 1;
- break;
- case 3:
- traintype = 3;
- trainloop = 0;
- seatloop = 1;
- break;
- case 9:
- timeloop = 1;
- trainloop = 0;
- seatloop = 0;
- break;
- default:
- trainloop = 1;
- seatloop = 0;
- break;
- }
- while (seatloop == 1)
- {
- seating = seatingf();
- switch (seating)
- {
- case 1:
- seattype = 1;
- agediscloop = 1;
- seatloop = 0;
- break;
- case 2:
- seattype = 2;
- agediscloop = 1;
- seatloop = 0;
- break;
- case 9:
- trainloop = 1;
- seatloop = 0;
- agediscloop = 0;
- break;
- default:
- trainloop = 0;
- seatloop = 1;
- agediscloop = 0;
- break;
- }
- while (agediscloop == 1)
- {
- agedisc = agediscountf();
- switch (agedisc)
- {
- case 1: case 3:
- agediscmod = 0.5;
- agediscloop = 0;
- discloop = 1;
- break;
- case 2:
- agediscmod = 1.0;
- agediscloop = 0;
- discloop = 1;
- break;
- case 0:
- seatloop = 1;
- agediscloop = 0;
- discloop = 0;
- break;
- default:
- agediscloop = 1;
- discloop = 0;
- break;
- }
- while (discloop == 1)
- {
- discount = discountf();
- switch (discount)
- {
- case 0:
- discmod = 1.0;
- receiptloop = 1;
- discloop = 0;
- break;
- case 1:
- discmod = 0;
- receiptloop = 1;
- discloop = 0;
- break;
- case 2:
- discmod = 0.75;
- receiptloop = 1;
- discloop = 0;
- break;
- default:
- receiptloop = 0;
- discloop = 1;
- break;
- }
- while (receiptloop == 1)
- {
- arrivaltime = timecf(start, desti, time, traintype);
- fee = feef(start, desti, seattype, traintype, agediscmod, discmod, display);
- receiptf(start, desti, display, time, train, seating, arrivaltime, fee);
- receiptout.arrivaltime = arrivaltime;
- receiptout.dayr = display.dayd;
- receiptout.desti = desti;
- receiptout.fee = fee;
- receiptout.monthr = display.monthd;
- receiptout.seating = seating;
- receiptout.start = start;
- receiptout.train = train;
- receiptout.time = time;
- receiptout.fee = fee;
- receiptoutf(receiptout);
- system("PAUSE");
- receiptloop = 0;
- discloop = 0;
- agediscloop = 0;
- seatloop = 0;
- trainloop = 0;
- timeloop = 0;
- dateloop = 0;
- destiloop = 0;
- startloop = 0;
- menuloop = 1;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } while (menuloop != 0);
- return 0;
- }
- int menu()
- {
- char menuinput[30];
- int loop;
- system("CLS");
- printf("\t+=================================================================+\n");
- printf("\t| |\n");
- printf("\t| Tokaido Shinkansen Ticket Reservation System |\n");
- printf("\t| |\n");
- printf("\t+=================================================================+\n");
- printf("\n\t\t1. Reserve Tickets\n");
- printf("\t\t9. Exit\n\n");
- printf("\n\n\n\n>> ");
- fflush(stdin);
- gets_s(menuinput);
- if (_strcmpi(menuinput,"1") == 0)
- {
- loop = 1;
- }
- else
- {
- if (_strcmpi(menuinput,"2") == 0)
- {
- loop = 2;
- }
- else
- {
- if (_strcmpi(menuinput,"9") == 0)
- {
- loop = 0;
- }
- else
- {
- loop = 9;
- }
- }
- }
- return loop;
- }
- int startf()
- {
- char startinput[30];
- int loop;
- system("CLS");
- printf("\n\t\t\t Starting station");
- printf("\n\n\n\n\t Tokyo(1) Nagoya(2) Shin-Osaka(3)");
- printf("\n | | |");
- printf("\n ===========+====================+=====================================+=======");
- printf("\n\n\t\t\t Type 9 to return to main menu.");
- printf("\n\n\n\n>> ");
- fflush(stdin);
- gets_s(startinput);
- if (_strcmpi(startinput,"Tokyo") == 0)
- {
- loop = 1;
- }
- else
- {
- if (_strcmpi(startinput,"1") == 0)
- {
- loop = 1;
- }
- else
- {
- if (_strcmpi(startinput,"Nagoya") == 0)
- {
- loop = 2;
- }
- else
- {
- if(_strcmpi(startinput,"2") == 0)
- {
- loop = 2;
- }
- else
- {
- if (_strcmpi(startinput,"Shin-Osaka") == 0)
- {
- loop = 3;
- }
- else
- {
- if (_strcmpi(startinput,"3") == 0)
- {
- loop = 3;
- }
- else
- {
- if (_strcmpi(startinput,"9") == 0)
- {
- loop = 0;
- }
- else
- {
- loop = 9;
- }
- }
- }
- }
- }
- }
- }
- return loop;
- }
- int destif (int start)
- {
- int desti;
- char destination[30];
- switch (start)
- {
- case 1:
- system("CLS");
- printf("\n\t\t\t Destination");
- printf("\n\n\n\n\t Nagoya(2) Shin-Osaka(3)");
- printf("\n | |");
- printf("\n ================================+=====================================+=======");
- printf("\n\n\t\tType 9 to return to starting station selection.");
- printf("\n\n\n\n>> ");
- fflush(stdin);
- gets_s(destination);
- if (_strcmpi(destination,"nagoya") == 0)
- {
- desti = 2;
- }
- else
- {
- if (_strcmpi(destination,"2") == 0)
- {
- desti = 2;
- }
- else
- {
- if (_strcmpi(destination,"shin-osaka") == 0)
- {
- desti = 3;
- }
- else
- {
- if (_strcmpi(destination,"3") == 0)
- {
- desti = 3;
- }
- else
- {
- if (_strcmpi(destination,"9") == 0)
- {
- desti = 9;
- }
- else
- {
- desti = 4;
- }
- }
- }
- }
- }
- break;
- case 2:
- system("CLS");
- printf("\n\t\t\t Destination");
- printf("\n\n\n\n\t Tokyo(1) Shin-Osaka(3)");
- printf("\n | |");
- printf("\n ===========+==========================================================+=======");
- printf("\n\n\t\tType 9 to return to starting station selection.");
- printf("\n\n\n\n>> ");
- fflush(stdin);
- gets_s(destination);
- if (_strcmpi(destination,"tokyo") == 0)
- {
- desti = 1;
- }
- else
- {
- if (_strcmpi(destination,"1") == 0)
- {
- desti = 1;
- }
- else
- {
- if (_strcmpi(destination,"shin-osaka") == 0)
- {
- desti = 3;
- }
- else
- {
- if (_strcmpi(destination,"3") == 0)
- {
- desti = 3;
- }
- else
- {
- if (_strcmpi(destination,"9") == 0)
- {
- desti = 9;
- }
- else
- {
- desti = 9;
- }
- }
- }
- }
- }
- break;
- case 3:
- system("CLS");
- printf("\n\t\t\t Destination");
- printf("\n\n\n\n\t Tokyo(1) Nagoya(2)");
- printf("\n | |");
- printf("\n ===========+====================+=============================================");
- printf("\n\n\t\tType 9 to return to starting station selection.");
- printf("\n\n\n\n>> ");
- fflush(stdin);
- gets_s(destination);
- if (_strcmpi(destination,"tokyo") == 0)
- {
- desti = 1;
- }
- else
- {
- if (_strcmpi(destination,"1") == 0)
- {
- desti = 1;
- }
- else
- {
- if (_strcmpi(destination,"nagoya") == 0)
- {
- desti = 2;
- }
- else
- {
- if (_strcmpi(destination,"2") == 0)
- {
- desti = 2;
- }
- else
- {
- if (_strcmpi(destination,"9") == 0)
- {
- desti = 9;
- }
- else
- {
- desti = 9;
- }
- }
- }
- }
- }
- break;
- }
- return desti;
- }
- int confirmation(int start, int desti)
- {
- char input[500];
- int inputi, confirm,confirmloop=1;
- while (confirmloop == 1)
- {
- system("CLS");
- printf("\n\t\t\tConfirmation Screen\n");
- switch (start)
- {
- case 1:
- printf("\nStarting Station: Tokyo\n");
- break;
- case 2:
- printf("\nStarting Station: Nagoya\n");
- break;
- case 3:
- printf("\nStarting Station: Shin-Osaka\n");
- break;
- }
- switch (desti)
- {
- case 1:
- printf("\nDestination: Tokyo\n");
- break;
- case 2:
- printf("\nDestination: Nagoya\n");
- break;
- case 3:
- printf("\nDestination: Shin-Osaka\n");
- break;
- }
- printf("\nEnter 1 to confirm starting station and destination");
- printf("\nEnter 2 to choose starting station");
- printf("\nEnter 3 to choose destination");
- printf("\n\n\n\n>>");
- gets(input);
- inputi = atoi(input);
- switch (inputi)
- {
- case 1:
- confirm = 1;
- confirmloop = 0;
- break;
- case 2:
- confirm = 2;
- confirmloop = 0;
- break;
- case 3:
- confirm = 3;
- confirmloop = 0;
- break;
- default:
- confirmloop = 1;
- break;
- }
- }
- return confirm;
- }
- struct dates datef()
- {
- int month,loop,daysetting,day,dayloop;
- struct dates display;
- char dayf[500],monthf[500];
- system("CLS");
- printf("\n\t\t\tDate of departure\n");
- printf("\nMonth List: January(1) February(2) March(3) April(4) May(5) June(6) July(7)\n\t August(8) September(9) October(10) November(11) December(12)\n");
- printf("\n\n\n\n\n\n\n\nEnter month: ");
- fflush(stdin);
- gets_s(monthf);
- month = atoi(monthf);
- switch (month)
- {
- case 1: case 3: case 5: case 7: case 8: case 10: case 12:
- daysetting = 1;
- dayloop = 1;
- break;
- case 2:
- daysetting = 2;
- dayloop = 1;
- break;
- case 4: case 6: case 9: case 11:
- daysetting = 3;
- dayloop = 1;
- break;
- default:
- daysetting = 0;
- break;
- }
- if (daysetting == 1)
- {
- while (dayloop == 1)
- {
- system("CLS");
- printf("\n\t\t\tDate of departure\n");
- printf("\nList of days: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n");
- printf("\t 26 27 28 29 30 31\n");
- printf("\n\t Type 0 to return to month selection.\n");
- printf("\n\n\n\n\n\n\nEnter day: ");
- fflush(stdin);
- gets_s(dayf);
- day = atoi(dayf);
- if (day == 0)
- {
- dayloop = 0;
- daysetting = 0;
- }
- else
- {
- if (day < 0)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- if (day > 31)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- dayloop = 0;
- loop = 1;
- }
- }
- }
- }
- }
- else
- {
- if (daysetting == 2)
- {
- while (dayloop == 1)
- {
- system("CLS");
- printf("\n\t\t\tDate of departure\n");
- printf("\nList of days: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n");
- printf("\t 26 27 28\n");
- printf("\n\t Type 0 to return to month selection.\n");
- printf("\n\n\n\n\n\n\nEnter day: ");
- fflush(stdin);
- scanf_s("%d",&day);
- if (day == 0)
- {
- dayloop = 0;
- daysetting = 0;
- }
- else
- {
- if (day < 0)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- if (day > 28)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- dayloop = 0;
- loop = 1;
- }
- }
- }
- }
- }
- else
- {
- if (daysetting == 3)
- {
- while (dayloop == 1)
- {
- system("CLS");
- printf("\n\t\t\tDate of departure\n");
- printf("\nList of days: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n");
- printf("\t 26 27 28 29 30\n");
- printf("\n\t Type 0 to return to month selection.\n");
- printf("\n\n\n\n\n\n\nEnter day: ");
- scanf_s("%d",&day);
- if (day == 0)
- {
- dayloop = 0;
- daysetting = 0;
- }
- else
- {
- if (day < 0)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- if (day > 30)
- {
- printf("Invalid day.");
- system("PAUSE");
- }
- else
- {
- dayloop = 0;
- loop = 1;
- }
- }
- }
- }
- }
- }
- }
- display.monthd = month;
- display.dayd = day;
- display.dateloopd = loop;
- return display;
- }
- int timef()
- {
- char input[400];
- int inputi,loop;
- system("CLS");
- printf("\n\t\t\t Departure Time");
- printf("\n\n1. 1000");
- printf("\n2. 1200");
- printf("\n\n\t\tType 9 to return to date selection.");
- printf("\n\n\n\n\n\n\n>> ");
- fflush(stdin);
- gets_s(input);
- inputi = atoi(input);
- switch (inputi)
- {
- case 1:
- loop = 1000;
- break;
- case 2:
- loop = 1200;
- break;
- case 9:
- loop = 9;
- break;
- default:
- loop = 1;
- break;
- }
- return loop;
- }
- int trainf()
- {
- char input[500];
- int inputi;
- system("CLS");
- printf("\n\t\t\t Type of train");
- printf("\n\n1. Nozomi");
- printf("\n2. Hikari");
- printf("\n3. Kodama");
- printf("\n\n\t\t Type 9 to return to time selection.\n");
- printf("\n\n\n\n\n>> ");
- fflush(stdin);
- gets_s(input);
- inputi = atoi(input);
- return inputi;
- }
- int seatingf()
- {
- char input[500];
- int inputi;
- system("CLS");
- printf("\n\t\t\tType of seating\n");
- printf("\n1. First-class\n");
- printf("2. Economy\n");
- printf("\n\t\tType 9 to return to train selection\n");
- printf("\n\n\n\n\n\n>>");
- fflush(stdin);
- gets_s(input);
- inputi = atoi(input);
- return inputi;
- }
- int agediscountf()
- {
- char input[400];
- int inputi,age,loop=1;
- while (loop == 1)
- {
- system ("CLS");
- printf("\n\t\t\tAge\n");
- printf("\nSenior Citizens (60+): Half Price\n");
- printf("\nAdults: Full Price\n");
- printf("\nChildren (<12): Half Price\n");
- printf("\nType 0 to return to seating selection.\n");
- printf("\n\n\nEnter age: ");
- fflush(stdin);
- gets_s(input);
- inputi = atoi(input);
- if (inputi < 0)
- {
- system("CLS");
- printf("\n\n\n\n\t\t\t\tInvalid Age");
- system("PAUSE");
- loop = 1;
- }
- else
- {
- if (inputi == 0)
- {
- age = 0;
- loop = 0;
- }
- else
- {
- if (inputi > 12)
- {
- if (inputi > 60)
- {
- if (inputi > 150)
- {
- system("CLS");
- printf("\n\n\n\n\t\t\t\tInvalid Age");
- system("PAUSE");
- loop = 1;
- }
- else
- {
- age = 3;
- loop = 0;
- }
- }
- else
- {
- age = 2;
- loop = 0;
- }
- }
- else
- {
- age = 1;
- loop = 0;
- }
- }
- }
- }
- return age;
- }
- int discountf()
- {
- char input[500];
- float discountmod;
- system("CLS");
- printf("\n\t\t\t Discount\n");
- printf("\n\n\nEnter code here (Type 0 if there is no code): ");
- fflush(stdin);
- gets_s(input);
- if (_strcmpi(input,"kelvinstop") == 0)
- {
- printf("The ride is free.");
- system("PAUSE");
- }
- else
- {
- if (_strcmpi(input,"0") == 0)
- {
- discountmod = 0;
- }
- else
- {
- if (_strcmpi(input,"kelvindont") == 0)
- {
- discountmod = 0;
- }
- else
- {
- if (_strcmpi(input,"hhgqnnhb3y") == 0)
- {
- discountmod = 2;
- }
- else
- {
- system("CLS");
- printf("\n\n\n\n\t\t\tInvalid Code.\n\n");
- system("PAUSE");
- discountmod = 999;
- }
- }
- }
- }
- return discountmod;
- }
- int timecf(int start, int desti, int time, int traintype)
- {
- int totaltime, arrivaltime;
- if ((start == 1 && desti == 2 && traintype == 1) == 1)
- {
- totaltime = 130;
- }
- else
- {
- if ((start == 1 && desti == 3 && traintype == 1) == 1)
- {
- totaltime = 230;
- }
- else
- {
- if ((start == 2 && desti == 1 && traintype == 1) == 1)
- {
- totaltime = 130;
- }
- else
- {
- if ((start == 2 && desti == 3 && traintype == 1) == 1)
- {
- totaltime = 100;
- }
- else
- {
- if ((start == 3 && desti == 1 && traintype == 1) == 1)
- {
- totaltime = 230;
- }
- else
- {
- if ((start == 3 && desti == 2 && traintype == 1) == 1)
- {
- totaltime = 100;
- }
- else
- {
- if ((start == 1 && desti == 2 && traintype == 2) == 1)
- {
- totaltime = 145;
- }
- else
- {
- if ((start == 1 && desti == 3 && traintype == 2) == 1)
- {
- totaltime = 300;
- }
- else
- {
- if ((start == 2 && desti == 1 && traintype == 2) == 1)
- {
- totaltime = 145;
- }
- else
- {
- if ((start == 2 && desti == 3 && traintype == 2) == 1)
- {
- totaltime = 115;
- }
- else
- {
- if ((start == 3 && desti == 1 && traintype == 2) == 1)
- {
- totaltime = 300;
- }
- else
- {
- if ((start == 3 && desti == 2 && traintype == 2) == 1)
- {
- totaltime = 115;
- }
- else
- {
- if ((start == 1 && desti == 2 && traintype == 3) == 1)
- {
- totaltime = 245;
- }
- else
- {
- if ((start == 1 && desti == 3 && traintype == 3) == 1)
- {
- totaltime = 400;
- }
- else
- {
- if ((start == 2 && desti == 1 && traintype == 3) == 1)
- {
- totaltime = 245;
- }
- else
- {
- if ((start == 2 && desti == 3 && traintype == 3) == 1)
- {
- totaltime = 115;
- }
- else
- {
- if ((start == 3 && desti == 1 && traintype == 3) == 1)
- {
- totaltime = 400;
- }
- else
- {
- if ((start == 3 && desti == 2 && traintype == 3) == 1)
- {
- totaltime = 115;
- }
- else
- {
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- arrivaltime = totaltime + time;
- return arrivaltime;
- }
- void receiptf(int start, int desti, struct dates display, int time, int train, int seating, int arrivaltime, float fee)
- {
- system("CLS");
- printf("\n\t\t\t\tReceipt");
- switch (start)
- {
- case 1:
- printf("\nStarting Station: Tokyo\n");
- break;
- case 2:
- printf("\nStarting Station: Nagoya\n");
- break;
- case 3:
- printf("\nStarting Station: Shin-Osaka\n");
- break;
- }
- switch (desti)
- {
- case 1:
- printf("\nDestination: Tokyo\n");
- break;
- case 2:
- printf("\nDestination: Nagoya\n");
- break;
- case 3:
- printf("\nDestination: Shin-Osaka\n");
- break;
- }
- switch (seating)
- {
- case 1:
- printf("\nSeating Type: First Class\n");
- break;
- case 2:
- printf("\nSeating Type: Economy Class\n");
- break;
- }
- switch (train)
- {
- case 1:
- printf("\nTrain Type: Nozomi\n");
- break;
- case 2:
- printf("\nTrain Type: Hikari\n");
- break;
- case 3:
- printf("\nTrain Type: Kodama\n");
- break;
- }
- switch (time)
- {
- case 1000:
- printf("\nTime of Departure: 1000 hrs\n");
- printf("\nTime of Arrival: %d hrs\n",arrivaltime);
- break;
- case 1200:
- printf("\nTime of Departure: 1200 hrs\n");
- printf("\nTime of Arrival: %d hrs\n",arrivaltime);
- break;
- }
- printf("\nDate of Departure : %d/%d\n",display.dayd,display.monthd);
- printf("\nFee : %.2f JPY\n",fee);
- }
- float feef(int start, int desti,int seattype, int traintype, float agediscmod, float discmod, struct dates display)
- {
- int distance_t,destichoice=0,seat_p;
- float base_rate,base_price,datemod=0,date_p,fee;
- switch (start)
- {
- case 1:
- destichoice = 1;
- break;
- case 2:
- destichoice = 2;
- break;
- case 3:
- destichoice = 3;
- break;
- }
- while (destichoice == 1)
- {
- switch (desti)
- {
- case 2:
- distance_t = 342;
- break;
- case 3:
- distance_t = 515;
- break;
- }
- destichoice = 0;
- }
- while (destichoice == 2)
- {
- switch (desti)
- {
- case 1:
- distance_t = 342;
- break;
- case 3:
- distance_t = 173;
- break;
- }
- destichoice = 0;
- }
- while (destichoice == 3)
- {
- switch (desti)
- {
- case 1:
- distance_t = 515;
- break;
- case 2:
- distance_t = 173;
- break;
- }
- destichoice = 0;
- }
- switch (traintype)
- {
- case 1:
- base_rate = 0.1;
- break;
- case 2:
- base_rate = 0.07;
- break;
- case 3:
- base_rate = 0.04;
- break;
- }
- switch (seattype)
- {
- case 1:
- seat_p = 500;
- break;
- case 2:
- seat_p = 200;
- break;
- }
- if (display.monthd == 12)
- {
- if ((display.dayd > 22 && display.dayd < 26) == 1)
- {
- datemod = 1.5;
- }
- }
- else
- {
- datemod = 1.0;
- }
- //calculations
- base_price = (base_rate * (distance_t*1.0)) + seat_p;
- date_p = base_price * datemod;
- fee = date_p * agediscmod * discmod;
- return fee;
- }
- void receiptoutf(struct receipts receiptout)
- {
- FILE *fptr;
- fptr = fopen("receipt.txt","w");
- fprintf(fptr,"\t\t\t\tTokaido Shinkansen\n");
- fprintf(fptr,"\n\t\t+===================================+");
- switch (receiptout.start)
- {
- case 1:
- fprintf(fptr,"\n\t\t|Starting Station: Tokyo |\n");
- break;
- case 2:
- fprintf(fptr,"\n\t\t|Starting Station: Nagoya |\n");
- break;
- case 3:
- fprintf(fptr,"\n\t\t|Starting Station: Shin-Osaka |\n");
- break;
- }
- fprintf(fptr,"\t\t| |");
- switch (receiptout.desti)
- {
- case 1:
- fprintf(fptr,"\n\t\t|Destination: Tokyo |\n");
- break;
- case 2:
- fprintf(fptr,"\n\t\tDestination: Nagoya |\n");
- break;
- case 3:
- fprintf(fptr,"\n\t\tDestination: Shin-Osaka |\n");
- }
- fprintf(fptr,"\t\t| |");
- switch (receiptout.seating)
- {
- case 1:
- fprintf(fptr,"\n\t\t|Seating Type: First-Class |\n");
- break;
- case 2:
- fprintf(fptr,"\n\t\t|Seating Type: Economy |\n");
- break;
- }
- fprintf(fptr,"\t\t| |");
- switch (receiptout.train)
- {
- case 1:
- fprintf(fptr,"\n\t\t|Train Type: Nozomi |\n");
- break;
- case 2:
- fprintf(fptr,"\n\t\t|Train Type: Hikari |\n");
- break;
- case 3:
- fprintf(fptr,"\n\t\t|Train Type: Kodama |\n");
- break;
- }
- fprintf(fptr,"\t\t| |");
- switch (receiptout.time)
- {
- case 1000:
- fprintf(fptr,"\n\t\t|Time of Departure: 1000 hrs |\n");
- fprintf(fptr,"\t\t| |");
- fprintf(fptr,"\n\t\t|Time of Arrival: %d hrs |\n",receiptout.arrivaltime);
- break;
- case 1200:
- fprintf(fptr,"\n\t\t|Time of Departure: 1200 hrs |\n");
- fprintf(fptr,"\t\t| |");
- fprintf(fptr,"\n\t\t|Time of Arrival: %d hrs |\n",receiptout.arrivaltime);
- break;
- }
- fprintf(fptr,"\t\t| |");
- if ((receiptout.dayr > 9 && receiptout.dayr < 32) && (receiptout.monthr < 10) == 1)
- {
- fprintf(fptr,"\n\t\t|Date of Departure: %d/%d |\n",receiptout.dayr,receiptout.monthr);
- }
- else
- {
- if ((receiptout.monthr > 9 && receiptout.monthr < 13) && (receiptout.dayr < 10) == 1)
- {
- fprintf(fptr,"\n\t\t|Date of Departure: %d/%d |\n",receiptout.dayr,receiptout.monthr);
- }
- else
- {
- if (((receiptout.monthr > 9 && receiptout.monthr < 13) && (receiptout.dayr > 9 && receiptout.dayr < 32)) == 1)
- {
- fprintf(fptr,"\n\t\t|Date of Departure: %d/%d |\n",receiptout.dayr,receiptout.monthr);
- }
- else
- {
- fprintf(fptr,"\n\t\t|Date of Departure: %d/%d |\n",receiptout.dayr,receiptout.monthr);
- }
- }
- }
- fprintf(fptr,"\t\t| |");
- fprintf(fptr,"\n\t\t|Fee: %3.2f JPY |\n",receiptout.fee);
- fprintf(fptr,"\t\t+===================================+");
- fclose(fptr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement