#include <stdio.h>
#define
MAX_ITEM 2
#define
REG_HAM_CODE 1
#define COKE_CODE 2
#define
REG_HAM_PRICE 2000
#define COKE_PRICE 1000
main()
{
int flag; /*
flag for scanf */
int processing; /*
1 for processing, 0 for end of processing */
int item_code; /*
for menu item code */
int number; /*
the number of item */
int no_of_reg_ham; /*
for one customer */
int no_of_coke;
int sub_total; /*
subtotal */
int personal_total; /*
total price for one customer */
/*
init process */
flag
= 1;
processing
= 1;
no_of_reg_ham
= 0;
no_of_coke
= 0;
personal_total
= 0;
while
(flag == 1 && processing == 1) {
/*
print out the menu */
printf("\n****************************************");
printf("\n*
%2d. Regular hamburger %14d *", REG_HAM_CODE, REG_HAM_PRICE);
printf("\n*
%2d. Coke
%14d *", COKE_CODE, COKE_PRICE);
printf("\n****************************************");
printf("\n
Enter the item code (0 for quit) : ");
flag
= scanf("%d", &item_code);
if
(flag == 1) {
if
((item_code > 0) && (item_code < MAX_ITEM + 1)) {
printf("
Enter the number : ");
flag
= scanf("%d", &number);
if
(flag == 1) {
if
((item_code == REG_HAM_CODE) && (number >= 0)) {
no_of_reg_ham
= no_of_reg_ham + number;
}
else
if ((item_code == COKE_CODE) && (number >= 0)) {
no_of_coke
= no_of_coke + number;
}
else
{
printf("\n
Error --- Check the number !!\n");
}
}
else
{
processing
= 0;
}
}
else
if (item_code == 0) {
processing
= 0;
}
else
{
printf("\n
Error --- Check the item code !!\n");
}
}
else
{
processing
= 0;
}
}
/* while - for one customer */
/*
print a result */
printf("\n----------------------------------------");
sub_total
= no_of_reg_ham * REG_HAM_PRICE;
personal_total
= personal_total + sub_total;
printf("\n
Regular Hamberger : %2d %14d", no_of_reg_ham, sub_total);
sub_total
= no_of_coke * COKE_PRICE;
personal_total
= personal_total + sub_total;
printf("\n
Coke : %2d %14d",
no_of_coke, sub_total);
printf("\n----------------------------------------");
printf("\n
TOTAL: %30d\n", personal_total);
printf("\nBye\n");
}