- 分享
- 0
- 人气
- 0
- 主题
- 13
- 帖子
- 8090
- UID
- 86649
- 积分
- 8388
- 阅读权限
- 24
- 注册时间
- 2007-7-10
- 最后登录
- 2017-3-8
- 在线时间
- 1726 小时
|
這是我整個Source Code
- #include <stdio.h>
- #include <time.h>
- #include <conio.h>
- #include <math.h>
- void main()
- {
- int lock, tbnum, pzchoice, pzquantity, drkchoice, drkquantity;
- char getmember, memberstat, membertype_get, membertype, pzsize_get, pzsize, pizza[12], drink[22],dispdiscount[5], memberdesc[22], custname[175]; // custname array based on World's Longest Name of a Person which has 174 characters
- float pzprice, drkprice, calcdiscount, pzsubtotal, drksubtotal, totalchrg, amountdc, discounted, tax, total, round, rounded, totalpay, paid, change;
- struct tm * timeinfo;
- time_t lt;
-
- puts("=====================================\n");
- puts("- WELCOME TO PIZZA HOUSE RESTAURANT -\n");
- puts("=====================================\n");
- puts("\n- MEMBERSHIP TYPES\n");
- puts(" G - Gold Class Member\n P - Platinum Class Member\n");
- puts("\n- PIZZA SIZES\n");
- puts(" L - Large (12\")\n R - Regular (9\")\n P - Personal (6\")\n");
- puts("\n- PIZZA FAVOURITES\n");
- puts(" 1. Pepperoni\n 2. Seafood\n 3. Vegetable\n 4. Hawaiian\n 5. Mixed Combo\n");
- puts("\n- DRINKS\n");
- puts(" 1. Orange Juice\n 2. Coffee\n 3. Mineral Water (600ml)\n 4. Pepsi\n");
- // Prompt customer's individual & order informations.
- printf("\nPlease enter your name\t: ");
- gets(custname);
- fflush(stdin);
- printf("Are you a member? (Y/N)\t: ");
- // Limits user input to Y and N only.
- lock = 0;
- do {
- getmember = getch();
- switch(getmember) {
- case 'Y':
- case 'y':
- if (lock == 0) {
- printf("Y");
- lock = 1;
- }
- else {
- printf("\bY");
- }
- memberstat = 'Y';
- break;
- case 'N':
- case 'n':
- if (lock == 0) {
- printf("N");
- lock = 1;
- }
- else {
- printf("\bN");
- }
- memberstat = 'N';
- break;
- case '\r':
- if (memberstat == 'Y' || memberstat == 'N'); {
- printf("\n");
- }
- break;
- default:
- if (lock != 1) {
- printf("\b%c", memberstat);
- lock = 0;
- }
- else {
- lock = 1;
- }
- break;
- }
- fflush(stdin);
- }
- while (getmember != '\r' || (memberstat != 'Y' && memberstat != 'N'));
- // Prompt member type decision...
- if (memberstat == 'Y') {
- printf("Membership Type? (G/P)\t: ");
- // Limits user input to G and P only.
- lock = 0;
- do {
- membertype_get = getch();
- switch(membertype_get) {
- case 'G':
- case 'g':
- if (lock == 0) {
- printf("G");
- lock = 1;
- }
- else {
- printf("\bG");
- }
- membertype = 'G';
- break;
- case 'P':
- case 'p':
- if (lock == 0) {
- printf("P");
- lock = 1;
- }
- else {
- printf("\bP");
- }
- membertype = 'P';
- break;
- case '\r':
- if (membertype == 'G' || membertype == 'P'); {
- printf("\n");
- }
- break;
- default:
- if (lock != 1) {
- printf("\b%c", membertype);
- lock = 0;
- }
- else {
- lock = 1;
- }
- break;
- }
- fflush(stdin);
- }
- while (membertype_get != '\r' || (membertype != 'G' && membertype != 'P'));
- }
- // Assign Member Description and Discount Amount
- switch (membertype) {
- case 'G':
- strcpy(memberdesc, "Gold Class Member");
- calcdiscount = 0.1;
- strcpy(dispdiscount, "10%");
- break;
- case 'P':
- strcpy(memberdesc, "Platinum Class Member");
- calcdiscount = 0.2;
- strcpy(dispdiscount, "20%");
- break;
- default:
- strcpy(memberdesc, "Non Member");
- calcdiscount = 0;
- strcpy(dispdiscount, "0%");
- break;
- }
- printf("Table Number\t\t: ");
- // Is the input an integer?
- while (scanf("%d", &tbnum) != 1) {
- puts("\aERROR\nInvalid table number!\n");
- printf("Table Number\t\t: ");
- scanf("%d", &tbnum);
- fflush(stdin);
- }
- printf("Choice of Pizza\t\t: ");
- // When Input is Invalid, display ERROR (SLIGHTLY BUGGED)
- while((scanf("%d", &pzchoice) != 1) || (pzchoice <= 0) || (pzchoice >= 6)) {
- puts("\aERROR\nInvalid choice of pizza!\n");
- printf("Choice of Pizza\t\t: ");
- scanf("%d", &pzchoice);
- fflush(stdin);
- }
- // Assign Pizza Name
- switch (pzchoice) {
- case 1:
- strcpy(pizza, "Pepperoni");
- break;
- case 2:
- strcpy(pizza, "Seafood");
- break;
- case 3:
- strcpy(pizza, "Vegetable");
- break;
- case 4:
- strcpy(pizza, "Hawaiian");
- break;
- case 5:
- strcpy(pizza, "Mixed Combo");
- break;
- }
- printf("Pizza Size? (L/R/P)\t: ");
- // Limits user input to L, R and P only.
- lock = 0;
- do {
- pzsize_get = getch();
- switch(pzsize_get) {
- case 'L':
- case 'l':
- if (lock == 0) {
- printf("L");
- lock = 1;
- }
- else {
- printf("\bL");
- }
- pzsize = 'L';
- break;
- case 'R':
- case 'r':
- if (lock == 0) {
- printf("R");
- lock = 1;
- }
- else {
- printf("\bR");
- }
- pzsize = 'R';
- break;
- case 'P':
- case 'p':
- if (lock == 0) {
- printf("P");
- lock = 1;
- }
- else {
- printf("\bP");
- }
- pzsize = 'P';
- break;
- case '\r':
- if (pzsize == 'L' || pzsize == 'R' || pzsize == 'P'); {
- printf("\n");
- }
- break;
- default:
- if (lock != 1) {
- printf("\b%c", pzsize);
- lock = 0;
- }
- else {
- lock = 1;
- }
- break;
- }
- fflush(stdin);
- }
- while (pzsize_get != '\r' || (pzsize != 'L' && pzsize != 'R' && pzsize != 'P'));
- // Assign Pizza Price and Size Description
- switch (pzsize) {
- case 'L':
- pzprice = 25.90;
- break;
- case 'R':
- pzprice = 18.90;
- break;
- case 'P':
- pzprice = 9.00;
- break;
- }
- printf("Quantity of Pizza\t: ");
- // Is the input an integer?
- while (scanf("%d", &pzquantity) != 1) {
- puts("\aERROR\nInvalid number of pizza!\n");
- printf("Quantity of Pizza\t: ");
- scanf("%d", &pzquantity);
- fflush(stdin);
- }
- printf("Choice of Drink\t\t: ");
- // When Input is Invalid, display ERROR (SLIGHTLY BUGGED)
- while((scanf("%d", &drkchoice) != 1) || (drkchoice <= 0) || (drkchoice >= 5)) {
- puts("\aERROR\nInvalid choice of drink!\n");
- printf("Choice of Drink\t\t: ");
- scanf("%d", &drkchoice);
- fflush(stdin);
- }
- // Assign Drink Name and Price
- switch (drkchoice) {
- case 1:
- strcpy(drink, "Orange Juice");
- drkprice = 3.20;
- break;
- case 2:
- strcpy(drink, "Coffee");
- drkprice = 3.00;
- break;
- case 3:
- strcpy(drink, "Mineral Water (600ml)");
- drkprice = 2.20;
- break;
- case 4:
- strcpy(drink, "Pepsi");
- drkprice = 2.50;
- break;
- }
- printf("Quantity of Drink\t: ");
- scanf("%d", &drkquantity);
- // Calculations
- pzsubtotal = pzprice * pzquantity;
- drksubtotal = drkprice * drkquantity;
- totalchrg = pzsubtotal + drksubtotal;
- amountdc = totalchrg * calcdiscount;
- discounted = totalchrg - amountdc;
- // Order Summary
- puts("\n- ORDER SUMMARY\n");
- // Date & Time
- time(<);
- timeinfo = localtime(<);
- printf("%s\n", asctime(timeinfo));
- printf("(Table %d)\n", tbnum);
- printf("Customer Name\t: %s\n", custname);
- printf("Membership Type\t: %s (%s Discount)\n", memberdesc, dispdiscount);
- puts("=====================================================================\n");
- printf(" %-6s%-24s%-15s%-13s%-s\n", "Size", "Item", "Unit Price", "Quantity", "Sub-Total");
- puts("=====================================================================\n");
- printf(" %-6c%-24sRM %6.2f%10d%10s %6.2f\n", pzsize, pizza, pzprice, pzquantity, "RM", pzsubtotal);
- printf(" %-6s%-24sRM %6.2f%10d%10s %6.2f\n", "-", drink, drkprice, drkquantity, "RM", drksubtotal);
- printf("%69s\n", "-----------");
- printf("%61s%6.2f\n", "Total Charge : RM", totalchrg);
- printf("%52s%s%5s%6.2f\n", "Discount (", dispdiscount, ") : RM", amountdc);
- printf("%69s\n", "-----------");
- printf("%61s%6.2f\n", "Discounted Price : RM", discounted);
- // Calculate Tax
- tax = discounted * 0.1;
- printf("%61s%6.2f\n", "Service Tax (10%) : RM", tax);
- printf("%69s\n", "-----------");
- // Calculate Total
- total = discounted + tax;
- printf("%61s%6.2f\n", "Total : RM", total);
- // Calculate Roundings
- rounded = ceil(total * 10) / 10;
- round = rounded - total;
- printf("%61s%6.2f\n", "Rounding Adjustment : RM", round);
- // Calculate Payment
- totalpay = total + round;
- printf("%69s\n", "-----------");
- printf("%61s%6.2f\n", "Total payment : RM", totalpay);
- printf("%69s\n\n", "===========");
- printf("%62s", "Paid Cash : RM ");
- scanf("%f", &paid);
- // Ensure paid amount is more than total payment
- while (paid < totalpay) {
- printf("%66s","\aERROR\n");
- printf("%80s","Insufficient amount!\n");
- printf("%62s", "Paid Cash : RM ");
- scanf("%f", &paid);
- fflush(stdin);
- }
- // Calculate Change
- change = paid - totalpay;
- printf("%61s%6.2f\n", "Change : RM", change);
- // Display Thank You Message
- puts("ALWAYS THE PREFERRED CHOICE!\n");
- puts("Pizza House Restaurant (482123-0)\n53300 Setapak, Kuala Lumpur.\n");
- printf("\n%s, thank you for visiting Pizza House Restaurant (482123-0)!\nHave a nice day, Please come again ~", custname);
- }
复制代码 |
|