The owner of SAYANG restaurant distributes brochures to his customers informing discounts
offered on selected menu for the month of July. To be eligible for the discount, a customer
must order any three items of the menu. The discount for each item in the menu is shown in
the table below.
Item
No. Menu Discount
1. Appetizers 10%
2 .Salads 10%
3 .Soups 20%
4 .Seafood 8%
5 .Chicken/Beef 15%
6 .Noodles/Rice 20%
7 .Vegetables 25%
8 .Pasta 15%
9 .Beverages 20%
10. Lunch Special 25%
11 .Healthy Food 15%
12 .Others 5%
The restaurant owner has requested you to write a program in C that reads the three ordered
items and their normal prices. The program calculates the total amount to be billed to the
customer based on the discount given for each item.
Sample program code
#include<stdio.h>
void main() {
int a, b, c;
float p1, p2, p3, m1, m2, m3, sum;
printf("Enter number item\t");
scanf("%d", &a);
printf("Enter price for the item");
scanf("%f", &p1);
if (a == 1)
m1 = p1 - (p1 * 10 / 100);
else if (a == 2)
m1 = p1 - (p1 * 10 /100);
else if (a == 3)
m1 = (p1 - p1 * 20 / 100);
else if (a == 4)
m1 = p1 - (p1 * 8 / 100);
else if (a == 5)
m1 = p1 - (p1 * 15 / 100);
else if (a == 6)
m1 = p1 - (p1 * 20 / 100);
else if (a == 7)
m1 = p1 - (p1 * 25 / 100);
else if (a == 8)
m1 = p1 - (p1 * 15 / 100);
else if (a == 9)
m1 = p1 - (p1 * 20 / 100);
else if (a == 10)
m1 = p1 - (p1 * 25 / 100);
else if (a == 11)
m1 = p1 - (p1 * 15 / 100);
else if (a == 12)
m1 = p1 - (p1 * 5 / 100);
printf("The price for the item after discount is RM%.2f\n", m1);
printf("Enter number item\t");
scanf("%d", &b);
printf("Enter price for the item");
scanf("%f", &p2);
if (b == 1)
m2 = p2 - (p2 * 10 / 100);
else if (b == 2)
m2 = p2 - (p2 * 10 /100);
else if (b == 3)
m2 = (p2 - p2 * 20 / 100);
else if (b == 4)
m2 = p2 - (p2 * 8 / 100);
else if (b == 5)
m2 = p2 - (p2 * 15 / 100);
else if (b == 6)
m2 = p2 - (p2 * 20 / 100);
else if (b == 7)
m2 = p2 - (p2 * 25 / 100);
else if (b == 8)
m2 = p2 - (p2 * 15 / 100);
else if (b == 9)
m2 = p2 - (p2 * 20 / 100);
else if (b == 10)
m2 = p2 - (p2 * 25 / 100);
else if (b == 11)
m2 = p2 - (p2 * 15 / 100);
else if (b == 12)
m2 = p2 - (p2 * 5 / 100);
printf("The price for the item after discount is RM%.2f\n", m2);
printf("Enter number item\t");
scanf("%d", &c);
printf("Enter price for the item");
scanf("%f", &p3);
if (c == 1)
m3 = p3 - (p3 * 10 / 100);
else if (c == 2)
m3 = p3 - (p3 * 10 /100);
else if (c == 3)
m3 = (p3 - p3 * 20 / 100);
else if (c == 4)
m3 = p3 - (p3 * 8 / 100);
else if (c == 5)
m3 = p3 - (p3 * 15 / 100);
else if (c == 6)
m3 = p3 - (p3 * 20 / 100);
else if (c == 7)
m3 = p3 - (p3 * 25 / 100);
else if (c == 8)
m3 = p3 - (p3 * 15 / 100);
else if (c == 9)
m3 = p3 - (p3 * 20 / 100);
else if (c == 10)
m3 = p3 - (p3 * 25 / 100);
else if (c == 11)
m3 = p3 - (p3 * 15 / 100);
else if (c == 12)
m3 = p3 - (p3 * 5 / 100);
printf("The price for the item after discount is RM%.2f\n", m3);
sum = m1 + m2 + m3;
printf("The total amount after discount is RM%.2f\n", sum);
}
0 comments:
Post a Comment