#include <stdio.h>
#define
REG_HAM 2000
#define COKE 1000
#define
MAX_ITEM 2
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_item1; /*
for one customer */
int no_of_item2;
int sub_total; /*
subtotal */
int personal_total; /*
total price for one customer */
/*
init process */
flag
= 1;
processing
= 1;
no_of_item1
= 0;
no_of_item2
= 0;
personal_total
= 0;
while
(flag == 1 && processing == 1) {
/*
print out the menu */
printf("\n****************************************");
printf("\n*
1. Regular hamburger %15d *", REG_HAM);
printf("\n*
2. Coke
%15d *", COKE);
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 == 1) && (no_of_item1 + number >= 0)) {
no_of_item1
= no_of_item1 + number;
}
else
if ((item_code == 2) && (no_of_item2+number >=0)) {
no_of_item2
= no_of_item2 + 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 */
if
(no_of_item1 + no_of_item2) {
printf("\n----------------------------------------");
if
(no_of_item1 > 0) {
sub_total
= no_of_item1 * REG_HAM;
personal_total
= personal_total + sub_total;
printf("\n
Regular Hamberger : %2d %14d", no_of_item1, sub_total);
}
if
(no_of_item2 > 0) {
sub_total
= no_of_item2 * COKE;
personal_total
= personal_total + sub_total;
printf("\n
Coke :
%2d %14d", no_of_item2, sub_total);
}
printf("\n----------------------------------------");
printf("\n
TOTAL: %30d\n", personal_total);
}
/* print a result */
printf("\nBye\n");
}