Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me to change this conding from cin to scanf and change strpcy to something simple like int or printf or idk because

can someone help me to change this conding from cin to scanf and change strpcy to something simple like int or printf or idk because it out of my syllabus . and also run the programme.

#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 printf("Drink No DrinkName \t Cost \t quantity "); for(i=0;i<=4;i++){ printf("%d \t",(i+1)); printf("%s \t$ %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 : "); 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){ printf("Enter money you want to insert : "); cin >> moneyInserted; if(moneyInserted<0 || moneyinserted> 1) printf("Can't accept money "); else if(moneyInserted >= drinks[choice-1].cost){ //change is displayed to the user printf("Change : $ %f ",(moneyInserted-drinks[choice-1].cost)); //that drinks cost is added here to the total Revenue totalRevenue = totalRevenue + drinks[choice-1].cost;

drinks[choice-1].quantitiy--; } else printf("Insufficient Funds "); } else if (choice == 6){ //if choice is six we will display revenu and drinks with their quantity printf("Total Revenue : $ %f ", totalRevenue); printf("Drink \t Number Left "); for(i=0;i<=4;i++){ printf(" %s \t %d ",drinks[i].name , drinks[i].quantitiy); } } else{ // if choice is not 6 and the drink is sold out then sold out will be shown printf("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_2

Step: 3

blur-text-image_3

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago