The question -
Write a program that gets user selection on which item to purchase. Display the proper menu for this. User will enter P to select Pie and C to select Cake.
If user selects Pie, get user selection for 3 choices.
1 Apple Pie (RM 2.50)
2 - Chicken Pie (RM 4.00)
If user selects Cake, get user selection for 4 choices.
1 Chocolate Cake (RM 3.50)
2 Honey Fruit Cake (RM 3.80)
3 Prune Cake (RM 3.20)
Once the selection has been made, get user input for quantity. Display the total amount that user have to pay and item that user has selected. See the sample program execution below to guide you in writing the program.
Sample 1:
Enter [P] to select Pie
Enter [C] To select Cake
P
Enter the number to make a selection
'1' - Apple Pie (RM2.50)
'2' - Chicken Pie(RM4.00)
2
You've selected Chicken Pie
Please enter quantity: 10
The total price is RM 40.00
Sample 2:
Enter [P] to select Pie
Enter [C] To select Cake
C
Enter the number to make a selection
'1' - Chocolate Cake (RM 3.50)
'2' - Honey Fruit Cake (RM 3.80)
'3' - Prune Cake (RM 3.20)
1
You've selected Chocolate Cake
Please enter quantity: 5
The total price is RM 17.50
The problem is i can't compile.
this is my code :
Code:
#include<stdio.h>
#include<string.h>
int main()
{
int choice, quantity ;
float total_price, price;
char apple_pie, chicken_pie, beef_pie, chocholate_cake, honey_fruit_cake, prune_cake;
printf("\n Enter [P] to select Pie : ");
printf("\n Enter [C] to select Pie : ");
scanf("%d" ,&choice);
while (choice=='p')
{
printf("\n '1' - Apple_pie (RM2.50) ");
printf("\n '2' - Chicken_pie (RM4.00) ");
printf("\n '3' - Beef_pie (RM4.00) ");
if (choice==1)
{
//strcpy(choice, "Apple_pie");
price = 2.50 ;
printf("\nYou've selected %d " , choice );
}
else if(choice==2)
{
//strcpy(choice, "Chicken_pie");
price = 4.00;
printf("\nYou've selected %d " , choice );
}
else if (choice==3)
{//strcpy(choice, "Beef_pie");
price = 4.00;
printf("\nYou've selected %d " , choice );
}
else
{
//strcpy(choice, "Invalid");
price=0.00 ;
}
do while (choice=='c')
{
printf("\n '1' - chocholate_cake (RM2.50) ");
printf("\n '2' - honey_fruit_cake (RM4.00) ");
printf("\n '3' - prune_cake (RM4.00) ");
printf("\n '4' - pisang_cake (RM4.00) ");
if (choice==1)
{
//strcpy(choice, "chocholate_cake");
price = 2.50 ;
printf("\nYou've selected %d " , choice );
}
else if(choice==2)
{
//strcpy(choice, "honey_fruit_cake");
price = 4.00;
printf("\nYou've selected %d " , choice );
}
else if (choice==3)
{
//strcpy(choice, "prune_cake");
price = 4.00;
printf("\nYou've selected %d " , choice );
}
else if (choice==4)
{ //strcpy(choice, "pisang_cake");
price = 4.00;
printf("\nYou've selected %d " , choice );
}
else
{
//strcpy(choice, "Invalid");
price=0.00 ;
}
printf("\nPlease enter quantity ");
scanf("%d" ,&quantity);
total_price = quantity*price;
printf("\nThe total price is %.2f " , total_price);
getche();
}