Question: can someone help me, why when i run my programme and try to choose one drink it show can't accept your money ? here is
can someone help me, why when i run my programme and try to choose one drink it show can't accept your money ?
here is my coding:
#include
//structure to store data about drinks struct Drink{ char *name; float cost; int quantitiy; };
int main(){ int i,choice; float moneyInserted,totalRevenue=0; struct Drink drinks[5];//structure variable with array size 5 //initializing data drinks[0].name= "CocaCola"; drinks[0].cost = 2.50;drinks[0].quantitiy=5; drinks[1].name= "Pepsi Vanilla"; drinks[1].cost = 2.50;drinks[1].quantitiy=3; drinks[2].name= "Grape Fanta";drinks[2].cost = 2.00;drinks[2].quantitiy=3; drinks[3].name= "Sprite Soda"; drinks[3].cost = 2.00;drinks[3].quantitiy=5; drinks[4].name= "Mineral Water "; drinks[4].cost = 0.90;drinks[4].quantitiy=1; do{ //displays data to the user printf("Drink No DrinkName\t\tCost\t\t quantity "); for(i=0;i or enter 6 to quit : "); scanf("%d",&choice); //choice is not 6 and the quantity is present then we will ask user to enter money if(choice!=6 && drinks[choice-1].quantitiy>0){ printf("Enter money you want to insert : "); scanf("%f",&moneyInserted); if(moneyInserted 1) printf("Can't accept money "); else if(moneyInserted >= drinks[choice-1].cost){ printf("Change : RM %f ",(moneyInserted-drinks[choice-1].cost)); totalRevenue = totalRevenue + drinks[choice-1].cost; drinks[choice-1].quantitiy--; } else printf("Insufficient Funds "); } else if (choice == 6){ printf("Total Revenue : RM %f ", totalRevenue); printf("Drink \t Number Left "); for(i=0;i
here is my output;

X quantity Qty : 5 Qty: 3 Qty : 3 Qty : 5 Qty : 1 C:\Users\ASUS\Documents\Untitled1.exe Drink No DrinkName Cost CocaCola RM 2.500000 Pepsi Vanilla RM 2.500000 Grape Fanta RM 2.000000 4 Sprite Soda RM 2.000000 5 Mineral Water RM 0.900000 6. quit Select a drink or enter 6 to quit : 1 Enter money you want to insert : 3 Can't accept money Drink No DrinkName Cost CocaCola RM 2.500000 Pepsi Vanilla RM 2.500000 Grape Fanta RM 2.000000 4 Sprite Soda RM 2.000000 5 Mineral Water RM 0.900000 6. quit Select a drink or enter 6 to quit : quantity Qty : 5 Qty : 3 Qty : 3 Qty : 5 Qty : 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
