Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me to convert this coding from cout to printf ?? and can try to run it ? basically this is for my

can someone help me to convert this coding from cout to printf ?? and can try to run it ?

basically this is for my assignment project, i need help asap

#include #include using namespace std; //structure to store data about drinks struct Drink{ char name[30]; 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 strcpy(drinks[0].name,"Cola ");drinks[0].cost = 0.65;drinks[0].quantitiy= 20; strcpy(drinks[1].name,"Root Beer");drinks[1].cost = 0.70;drinks[1].quantitiy= 20; strcpy(drinks[2].name,"Grape Soda");drinks[2].cost = 0.75;drinks[2].quantitiy=20; strcpy(drinks[3].name,"Lemon-lime");drinks[3].cost = 0.85;drinks[3].quantitiy= 20; strcpy(drinks[4].name,"Water ");drinks[4].cost = 0.90;drinks[4].quantitiy=20; //do while loop runs atleast once and quits only when 6 is pressed do{ //displays data to the user cout << "Drink No DrinkName \t Cost \t quantity "; for(i=0;i<=4;i++){ cout << i+1 << "\t" ; cout << drinks[i].name << "\t$" << drinks[i].cost << "\tQty : " << drinks[i].quantitiy << " "; } cout << "6.\tquit "; cout << "Select a drink <1-5> or enter 6 to quit : "; cin >> 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){ cout << "Enter money you want to insert : "; cin >> moneyInserted; if(moneyInserted<0 || moneyinserted> 1) cout << "Can't accept money "; else if(moneyInserted >= drinks[choice-1].cost){ //change is displayed to the user cout << "Change : $ " << moneyInserted-drinks[choice-1].cost<<" "; //that drinks cost is added here to the total Revenue totalRevenue = totalRevenue + drinks[choice-1].cost;

drinks[choice-1].quantity--; } else cout << "Insufficient Funds "; } else if (choice == 6){ //if choice is six we will display revenu and drinks with their quantity cout << "Total Revenue : $"<< totalRevenue << " "; cout << "Drink \t Number Left "; for(i=0;i<=4;i++){ cout << drinks[i].name << "\t" << drinks[i].quantitiy << " "; } } else{ // if choice is not 6 and the drink is sold out then sold out will be shown cout<< "SOLD OUT "; } }while(choice!=6); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions