Whole food sells three types of high quality organic chocolate, customer can ord
ID: 3594060 • Letter: W
Question
Whole food sells three types of high quality organic chocolate, customer can order online. Here is a sample run: Menu 1) Dark Chocolate ($2.25/oz) 2) White Chocolate ($2/oz) 3) Milk Chocolate ($1.85/oz) 4) Quit Enter your choice: 1 Enter the quantity (oz): S Your total for dark chocolate is: $11.25 Here is another sample run: Menu 1) Dark Chocolate ($2.25/oz) 2) White Chocolate ($2/oz) 3) Milk Chocolate ($1.85/oz) 4) Quit Enter your choice: 2 Enter the quantity (oz):4 Your total for white chocolate is: $8 300Explanation / Answer
PLEASE REFER BELOW CODE
#include<stdlib.h>
#include<stdio.h>
int main()
{
float arr[3] = {2.25,2,1.85}; //array for per oz
int choice,quantity; //choice and quantity
float total; //total
//defining menu
printf("Menu ");
printf("1) Dark chocolates($2.25/oz) ");
printf("2) White chocolates($2/oz) ");
printf("3) Milk chocolates($1.85/oz) ");
printf("4) Quit ");
//taking user input for choice
printf(" Enter your choice : ");
scanf("%d", &choice);
//switch case for choice
switch(choice)
{
case 1:
//taking user input for quantity
printf(" Enter the quantity(oz) : ");
scanf("%d", &quantity);
total = quantity * arr[0];
printf("Your total for Dark chocolate is : $%f ", total);
break;
case 2:
//taking user input for quantity
printf(" Enter the quantity(oz) : ");
scanf("%d", &quantity);
total = quantity * arr[1];
printf("Your total for White chocolate is : $%f ", total);
break;
case 3:
//taking user input for quantity
printf(" Enter the quantity(oz) : ");
scanf("%d", &quantity);
total = quantity * arr[2];
printf("Your total for Milk chocolate is : $%f ", total);
break;
default:
break;
}
return 0;
}
PLEASE REFER BELOW OUTPUT
1)
Menu
1) Dark chocolates($2.25/oz)
2) White chocolates($2/oz)
3) Milk chocolates($1.85/oz)
4) Quit
Enter your choice : 1
Enter the quantity(oz) : 5
Your total for Dark chocolate is : $11.250000
Process returned 0 (0x0) execution time : 5.396 s
Press any key to continue.
2)
Menu
1) Dark chocolates($2.25/oz)
2) White chocolates($2/oz)
3) Milk chocolates($1.85/oz)
4) Quit
Enter your choice : 2
Enter the quantity(oz) : 4
Your total for White chocolate is : $8.000000
Process returned 0 (0x0) execution time : 7.081 s
Press any key to continue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.