- 分享
- 0
- 人气
- 0
- 主题
- 13
- 帖子
- 8090
- UID
- 86649
- 积分
- 8388
- 阅读权限
- 24
- 注册时间
- 2007-7-10
- 最后登录
- 2017-3-8
- 在线时间
- 1726 小时
|
- #include <stdio.h>
- #include <time.h>
- int main()
- {
- int tbnum, pznum, drknum, pzq, drkq;
- char custname[175], pz[12], drk[10]; // custname array based on World's Longest Name of a Person which has 174 characters
- const double pzpr = 8.50, drkpr = 3.20;
- double psub, dsub, ttch, ttpay, tax, paid, chg;
- struct tm * timeinfo;
- time_t lt;
-
- printf("\t--- Welcome to Pizza House Restaurant ---\n\n");
- // Show Pizza and Drinks Menu
- printf("PIZZA MENU\n 1.Pepperoni\n 2.Seafood\n 3.Vegetable\n 4.Hawaiian\n 5.Mixed Combo\n");
- printf("\nDRINKS MENU\n 1.Juice\n 2.Chocolate\n 3.Cocktail\n 4.Latte\n");
- // Prompt User Input on Order Information
- printf("\nPlease enter table number\t: ");
- scanf("%d", &tbnum);
- fflush(stdin);
- printf("Please enter your name\t\t: ");
- gets(custname);
- printf("Enter choice of pizza\t\t: ");
- scanf("%d", &pznum);
- fflush(stdin);
- // If Statement limiting the pizza choice
- if (pznum > 5) {
- printf("ERROR\nWe do not have that on the menu, please re-enter your choice!\n");
- printf("Enter choice of pizza\t\t: ");
- scanf("%d", &pznum);
- fflush(stdin);
- }
- else if (pznum < 1) {
- printf("ERROR\nWe do not have that on the menu, please re-enter your choice!\n");
- printf("Enter choice of pizza\t\t: ");
- scanf("%d", &pznum);
- fflush(stdin);
- }
- printf("Enter quantity of the pizza\t: ");
- scanf("%d", &pzq);
- fflush(stdin);
- printf("\nEnter choice of drink\t\t: ");
- scanf("%d", &drknum);
- fflush(stdin);
- // If Statement limiting the drink choice
- if (drknum > 4 ) {
- printf("ERROR\nWe do not have that on the menu, please re-enter your choice!\n");
- printf("Enter choice of drink\t\t: ");
- scanf("%d", &drknum);
- fflush(stdin);
- }
- else if (drknum < 1 ) {
- printf("ERROR\nWe do not have that on the menu, please re-enter your choice!\n");
- printf("Enter choice of drink\t\t: ");
- scanf("%d", &drknum);
- fflush(stdin);
- }
- printf("Enter quantity of the drink\t: ");
- scanf("%d", &drkq);
- fflush(stdin);
- // Show Order Summary
- printf("\nOrder Summary:\n--------------\n");
- time(<); // Get Date/Time
- timeinfo = localtime(<);
- printf("Date/Time\t: %s", asctime(timeinfo));
- printf("Table Number\t: %d\n", tbnum);
- printf("Customer Name\t: %s\n", custname);
- printf("\nItem\t\tUnit Price (RM)\t\tQuantity\tSub-Total (RM)\n");
- printf("-----\t\t---------------\t\t--------\t--------------\n");
- psub = pzpr * pzq;
- // If Statement identifying pizza type
- if (pznum == 1) {
- strcpy(pz, "Pepperoni");
- }
- if (pznum == 2) {
- strcpy(pz, "Seafood");
- }
- if (pznum == 3) {
- strcpy(pz, "Vegetable");
- }
- if (pznum == 4) {
- strcpy(pz, "Hawaiian");
- }
- if (pznum == 5) {
- strcpy(pz, "Mixed Combo");
- }
- printf("%-s\t\t%.2lf\t\t %d\t\t\t%.2lf\n", pz, pzpr, pzq, psub);
- dsub = drkpr * drkq;
- // If Statement identifying drink type
- if (drknum == 1) {
- strcpy(drk, "Juice");
- }
- if (drknum == 2) {
- strcpy(drk, "Chocolate");
- }
- if (drknum == 3) {
- strcpy(drk, "Cocktail");
- }
- if (drknum == 4) {
- strcpy(drk, "Latte");
- }
- printf("%-s\t\t%.2lf\t\t %d\t\t\t %.2lf\n", drk, drkpr, drkq, dsub);
- printf("\t\t\t\t\t\t\t--------------\n");
- ttch = psub + dsub;
- printf("\t\t\t\t\tTotal Charge:\t\t%.2lf\n", ttch);
- tax = ttch * 0.1;
- printf("\t\t\t\t\tService Tax(10%%):\t %.2lf\n", tax);
- ttpay = ttch + tax;
- printf("\t\t\t\t\t\t\t==============\n\t\t\t\t\tTotal Payment:\t\t%.2lf\n\t\t\t\t\t\t\t==============\n", ttpay);
- // Prompt User Input on Cash Paid
- printf("\t\t\t\t\tPaid Cash:\tRM\t");
- scanf("%lf", &paid);
- fflush(stdin);
- // Check Paid Amount, ensuring amount paid is more than total payment.
- if (paid < ttpay) {
- printf("ERROR\nAmount Paid is less than Total Payment, Please re-enter Paid Cash!\n");
- printf("\t\t\t\t\tPaid Cash:\tRM\t");
- scanf("%lf", &paid);
- fflush(stdin);
- }
- chg = paid - ttpay;
- printf("\t\t\t\t\tCHANGE:\t\tRM\t%.2lf\n", chg);
- printf("\nALWAYS THE PREFERRED CHOICE!\n");
- printf("\tPizza House Restaurant (482123-0)\n\t53300 Setapak, Kuala Lumpur.\n");
- printf("\n%s, thank you for visiting Pizza House Restaurant (482123-0)!!\nHave a nice day. Please come again ~~!", custname);
-
- return 0;
- }
复制代码
这是我新update的code,在if那里我发现如果触发那个情况的时候只能发生一次。比如说:
- if (paid < ttpay) {
- printf("ERROR\nAmount Paid is less than Total Payment, Please re-enter Paid Cash!\n");
- printf("\t\t\t\t\tPaid Cash:\tRM\t");
- scanf("%lf", &paid);
- fflush(stdin);
- }
复制代码
这段输入一个比Total还要少的数字就只能触发一次,第二次打少过Total的就照跑下去了。
我去Google了一下,发现可以用Loop,但又不怎么明白while的用法,能不能帮忙小弟指点迷津?
先谢谢了... |
|