Code:
#include <stdio.h>
#include <stdlib.h>
#define A "Candy"
#define A_P 4.55
#define B "Flour"
#define B_P 1.5
#define C "Soup"
#define C_P 2.88
#define D "Walnuts"
#define D_P 5.25
#define E "Rice"
#define E_P 1.05
#define F "Noodles"
#define F_P 0.35
#define G "Sugar"
#define G_P 0.92
#define H "Cake"
#define H_P 1.45
char menu (float candy_1 , float flour_1, float soup_1, float walnuts_1, float rice_1, float noodles_1, float sugar_1, float cake_1);
int main ()
{
char choice;
float candy_pound = 0, flour_pound = 0, soup_pound = 0 , walnuts_pound = 0, rice_pound = 0, noodles_pound = 0, sugar_pound = 0, cake_pound = 0;
printf("WECOME\n");
printf("Please PRESS ENTER FIRST and then choose from the following choices\n");
printf("Choice [A] for candy\n");
printf("Choice [B] for flour\n");
printf("Choice [C] for soup\n");
printf("Choice [D] for walnuts\n");
printf("Choice [E] for rice\n");
printf("Choice [F] for noodles\n");
printf("Choice [G] for sugar\n");
printf("Choice [H] for cake\n");
printf("Choice [R] to reset program\n");
scanf("%c", &choice);
while ((choice = getchar()) != '#')
{
switch(choice)
{
case 'A':
case 'a':
printf("Please enter number of pounds\n");
scanf("%f", &candy_pound);
while (candy_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&candy_pound);
}
break;
case 'B' :
case 'b':
printf("Please enter number of pounds\n");
scanf("%f", &flour_pound);
while (flour_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&flour_pound);
}
break;
case 'C' :
case 'c' :
printf("Please enter number of pounds\n");
scanf("%f", &soup_pound);
while (soup_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&flour_pound);
}
break;
case 'D':
case 'd':
printf("Please enter number of pounds\n");
scanf("%f", &walnuts_pound);
while (walnuts_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&walnuts_pound);
}
break;
case 'E':
case 'e':
printf("Please enter number of pounds\n");
scanf("%f", &rice_pound);
while (rice_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&rice_pound);
}
break;
case 'F':
case 'f':
printf("Please enter number of pounds\n");
scanf("%f", &noodles_pound);
while (noodles_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&noodles_pound);
}
break;
case 'G':
case 'g':
printf("Please enter number of pounds\n");
scanf("%f", &sugar_pound);
while (sugar_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&sugar_pound);
}
break;
case 'H':
case 'h':
printf("Please enter number of pounds\n");
scanf("%f", &cake_pound);
while (cake_pound<=0)
{
printf("\a\n");
printf("Oops, you have entered negative pound\n");
printf("Please try again\n");
scanf("%f",&cake_pound);
}
break;
case 'R':
case 'r':
{
candy_pound=0, flour_pound=0, soup_pound=0, walnuts_pound=0, rice_pound=0, noodles_pound=0, sugar_pound=0, cake_pound=0;
break;
}
case 'q':
case 'Q':
exit(0);
default :
printf("Oops you have entered invalid choice. Please choose again\n");
}
while (getchar() != '\n')
continue;
printf("Please enter another choice or enter # to checkout\n");
}
choice = menu(candy_pound, flour_pound, soup_pound, walnuts_pound, rice_pound, noodles_pound, sugar_pound, cake_pound);
}
char menu (float candy_1 , float flour_1, float soup_1, float walnuts_1, float rice_1, float noodles_1, float sugar_1, float cake_1)
{
char choice1;
float subtotal=0, totalpounds=0, averagecost=0, hst=0, total=0;
float candy_1_total =0 , flour_1_total = 0 , soup_1_total=0, walnuts_1_total=0, rice_1_total=0, noodles_1_total=0, sugar_1_total=0, cake_1_total=0;
candy_1_total = A_P* candy_1;
flour_1_total = B_P* flour_1;
soup_1_total = C_P* soup_1;
walnuts_1_total = D_P* walnuts_1;
rice_1_total = E_P* rice_1;
noodles_1_total = F_P* noodles_1;
sugar_1_total= G_P* sugar_1;
cake_1_total= H_P* cake_1;
subtotal = candy_1_total+ flour_1_total+ soup_1_total+ walnuts_1_total+ rice_1_total+ noodles_1_total+ sugar_1_total+ cake_1_total;
totalpounds = candy_1 + flour_1 + soup_1 + walnuts_1 + rice_1 + noodles_1 + sugar_1 + cake_1;
hst = subtotal * 0.13;
total = subtotal + hst;
if (subtotal > 0 && totalpounds > 0)
{
averagecost = subtotal/totalpounds;
}
printf(" WELCOME TO THE BULK FOOD STORE PROGRAM\n");
printf("Item \t Description \t Cost/LB \t\t # Pounds \t Subtotal\n");
printf("A\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",A, A_P, candy_1, candy_1_total);
printf("B\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",B, B_P, flour_1, flour_1_total);
printf("C\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",C, C_P, soup_1, soup_1_total);
printf("D\t\t %s\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",D, D_P, walnuts_1, walnuts_1_total);
printf("E\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",E, E_P, rice_1, rice_1_total);
printf("F\t\t %s\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",F, F_P, noodles_1, noodles_1_total);
printf("G\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",G, G_P, sugar_1, sugar_1_total);
printf("H\t\t %s\t\t\t %2.2f\t\t\t %2.2f\t\t $ %2.2f\n",H, H_P, cake_1, cake_1_total);
printf("\ntotal pounds = %2.2f\t\t\t SUBTOTAL\t$ %2.2f", totalpounds, subtotal);
printf("\nAvg Cost/Lb = %2.2f\t\t\tHST Ammount\t$ %2.2f", averagecost, hst);
printf("\n\n\t\t\t\t\t\tTOTAL Ammount\t$ %.2f", total);
printf("\n\nYour choice (R to RESET, Q to QUIT) ==>");
scanf("%c", &choice1);
return(choice1);
}