/*write the code for the following processSale function. Its purpose is take the
ID: 3626532 • Letter: #
Question
/*write the code for the following processSale function. Its purpose is take the array of drink
structures(first arg), the selection (2nd arg = which drink to purchase), and the cash (3rd arg=amount offered to pay for the drink) and produce the following results:
If the cash is more than $1.00, output the message "Cash amount too large!" and return.
If the cash is less than the price of the drink selected, output the message "Not enough cash!", and return.
If there are no drinks left for the selection, output "No XXXXX left! and return
If the cash is = > price of the drink selected, and there are drinks available for the selection,
a)out put the message:
XXXXXX purchased, your change is .YY"
b) subtract 1 from the number of drinks available for the selection.
Assume you have the following struct declaration for a drink given: */
struct Drink
{
string drinkName;
double price;
int numLeft;
};
const int SIZE=8;
void processSale(Drink drinkInfo[SIZE], int selection, double cash)
{
if(_____________)
cout << "Cash amount too large! ";
else if (________________>cash)
cout << "Not enough cash! ";
else if (_______________==0)
cout << "No" << _________________ << "left! ";
else
{
cout << ___________________
<< " purchased, your change is "
<< setprecision(2) << fixed <<
cash - _________________ << endl;
__________ --;
}
return;
}
Explanation / Answer
struct Drink
{
string drinkName;
double price;
int numLeft;
};
const int SIZE=8;
void processSale(Drink drinkInfo[SIZE], int selection, double cash)
{
if(cash > 1)
cout << "Cash amount too large! ";
else if (drinkinfo[selection].price>cash)
cout << "Not enough cash! ";
else if (drinkinfo[selection].numLeft==0)
cout << "No" << "Drinks " << "left! ";
else
{
cout << drinkinfo[selection].drinkName
<< " purchased, your change is "
<< setprecision(2) << fixed <<
cash - drinkinfo[selection].price << endl;
drinkinfo[selection].numLeft--;
}
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.