Question: can someone help me with flowchart and pseduo code ? here is my problem: Make a new programming to vending machine so that It will
can someone help me with flowchart and pseduo code ?
here is my problem:
Make a new programming to vending machine so that It will show the user a menu of items accessible by name and the price next to the object. When an item is sold out the menu reveals that the message next to the item is sold out and does not encourage the item to be picked.
here is my input:
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
if quantity is 0 , item is sold out
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<=4;i++){ printf("%d\t",(i+1)); printf("%s\t\tRM %f \t Qty : %d ",drinks[i].name , drinks[i].cost , drinks[i].quantitiy ); } printf("6.\tquit "); printf("Select a drink <1-5> 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<0 || 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<=4;i++){ printf(" %s \t %d ",drinks[i].name , drinks[i].quantitiy); } } else{ printf("SORRY, CURRENTLY SOLD OUT! "); } }while(choice!=6); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
