(16 points) Write the code f the array of Vendltem structures which is also t am
ID: 3908869 • Letter: #
Question
(16 points) Write the code f the array of Vendltem structures which is also t amount offered to pay for the item) and produce the following results or the following procSale function. Its purpose is to take (first argument), the selection (2nd argument, he array item to purchase), and the cash (3rd argument, which is the 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 item selected, output the message "Not enough cash!", and returrn If there are no items left for the selection, output "No XXXXX left!" and return . If the cash is or > price of the item selected, and there are items available for the selection o Output the message: X purchased, your change is 0.YY (where XXXXX is the drinkname and 0.YY is the change) Subtract 1 from the number of items available for the selection o Assume you have the following global declarations for a Vendltem given struct VendItem string itemName,; double price //all prices are .00 and multiples of .05 int numLeft;Explanation / Answer
void procScale(VendItem vendInfo[SIZE], int selection, double cash) {
VendItem itemSelected = vendInfo[selection];
if(cash > 1.00) {
printf("Cash amount too large!");
return;
}
if(cash < itemSelected.price) {
printf("Not enough cash!");
return;
}
if(itemSelected.numLeft == 0) {
printf("No %s left!", itemSelected.itemName);
return;
}
if(cash >= itemSelected.price && itemSelected.numLeft >= 1) {
printf("%s purchased, your change is %f", itemSelected.itemName, (cash - itemSelected.price));
itemSelected.numLeft = itemSelected.numLeft - 1;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.