#include <stdio.h>
#include <time.h>
int main()
{
int tbnum, pznum, drknum, pzq, drkq;
char custname[175], pz[12], drk[10];
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 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 Else 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 { // Do Nothing
}
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 Else 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 { // Do Nothing
}
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 (pznum == 1) {
pz = "Pepperoni";
}
else { // Do Nothing
}
printf("%-s\t\t%.2lf\t\t %d\t\t\t%.2lf\n", pz, pzpr, pzq, psub);
dsub = drkpr * drkq;
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);
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;
}
原帖由 Super-Tomato 于 2009-11-15 08:03 PM 发表
C 的 characters 和 String 不一樣, 不能直接 assign, 所以必須用 copy 的方式
strcpy(pz, " Pepperoni");
原帖由 ~Kai 于 2009-11-15 08:34 PM 发表
谢谢你的帮忙。
我还有一个问题,能不能Declare一个Array是没有限制的?
比如说 char sumthing[]; 这样的
我刚刚才发现另一个问题...
printf("\t\t\t\t\tService Tax(10%):\t %.2lf\n", tax);
这里面 ...
原帖由 Super-Tomato 于 2009-11-15 09:27 PM 发表
1. char sumthing[] = "here is your text";
2. printf("\t\t\t\t\tService Tax(10%%):\t %.2lf\n", tax);
原帖由 ~Kai 于 2009-11-28 03:04 PM 发表
#include
#include
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 chara ...
原帖由 Super-Tomato 于 2009-11-15 09:27 PM 发表
1. char sumthing[] = "here is your text";
2. printf("\t\t\t\t\tService Tax(10%%):\t %.2lf\n", tax);
原帖由 ~Kai 于 2009-11-15 08:34 PM 发表
谢谢你的帮忙。
我还有一个问题,能不能Declare一个Array是没有限制的?
比如说 char sumthing[]; 这样的
我刚刚才发现另一个问题...
printf("\t\t\t\t\tService Tax(10%):\t %.2lf\n", tax);
这里面 ...
原帖由 Super-Tomato 于 2009-11-28 05:15 PM 发表
while 就和 if 一樣只是需要條件值
#include
int main()
{
double ttpay, paid;
ttpay = 100;
while(paid < ttpay) {
printf("ERROR\nAmount P ...
欢迎光临 JBTALKS.CC (https://jbtalks.my/) | Powered by Discuz! X2.5 |