Write the code for the following procSale function. Its purpose is to take the a
ID: 3898079 • Letter: W
Question
Write the code for the following procSale function. Its purpose is to take the array of Vendltem structures (irst argument), the selection (2nd argument, which is also the array item to purchase), and the cash (3rd argument, which is the amount offered to pay for the item) 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 item selected, output the message "Not enough cash!", and return 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: "XXXXXX purchased, your . . · change is O.YY" (where XXXXX is the drinkname and O.YY is the change) o Subtract 1 from the number of items available for the selection Assume you have the following global declarations for a Vendltem given struct VendItem string itemName; double price; //a11 prices areExplanation / Answer
If you have any doubts, please give me comment....
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
using namespace std;
struct VendItem{
string itemName;
double price;
int numLeft;
};
const int SIZE = 8;
int main(){
return 0;
}
void procSale(VendItem vendInfo[SIZE], int selection, double cash){
if(cash>1.00){
cout<<"Cash amount too large!"<<endl;
return;
}
else if(cash<vendInfo[selection].price){
cout<<"Not enough cash!"<<endl;
return;
}
else if(vendInfo[selection].numLeft==0){
cout<<vendInfo[selection].itemName<<" left!"<<endl;
return;
}
else if(cash>=vendInfo[selection].price){
cout<<setprecision(2)<<fixed;
cout<<vendInfo[selection].itemName<<" purchased, your change is "<< cash - vendInfo[selection].price;
vendInfo[selection].numLeft--;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.