use the void to make a function called makeSale() see code below #include<iostre
ID: 3565010 • Letter: U
Question
use the void to make a function called makeSale() see code below
#include<iostream>
using namespace std;
int main()
{
int choice=0,salecount=0;
double cashRegister=0;
cout<<"Walgreens store Cash Register Manager"<<endl;
while(choice!=5)
{
cout<<endl;
cout<<"1- New Sale"<<endl;
cout<<"2- Cash Out"<<endl;
cout<<"3- Cash In"<<endl;
cout<<"4- Report"<<endl;
cout<<"5- Exit"<<endl;
cout<<"What do you want to do: ";
cin>>choice;
if(choice==1)
{
int itemcount=0,itemcode=0;
double weight=0,unitprice=0,unittotal=0;
cout<<"How many items in this sale: " ;
cin>>itemcount;
for(int i=1;i<=itemcount;i++)
{
cout<<"Item Code: ";
cin>>itemcode;
if(itemcode<100)
{
cout<<"Item price/pound: ";
cin >> unitprice;
cout<<"Item weight: ";
cin>>weight;
unitprice=unitprice*weight;
}
else
{
cout<<"Item price: ";
cin >> unitprice;
unitprice = unitprice + unitprice*0.1;
}
unittotal += unitprice;
}
cashRegister += unittotal;
salecount++;
}
else if(choice==2)
{
double amount;
cout<<"Cash-out amount? ";
cin>>amount;
if(amount<cashRegister)
{
cashRegister -= amount;
}
else
cout<<"Cash out amount cannot be greater than Cash Register amount. Please retry";
}
else if(choice==3)
{
double amount;
cout<<"Cash-in amount? ";
cin>>amount;
cashRegister += amount;
}
else if(choice==4)
{
cout<<"# of sales: " << salecount << endl;
cout<<"Total: " << cashRegister << endl;
}
else if(choice==5)
{
cout<<"Thank You"<<endl;
break;
}
else
cout<<"Invalid choice Please retry"<<endl;
}
return 0;
}
Explanation / Answer
#include<iostream>
using namespace std;
int salecount=0;
double cashRegister=0;
void makeSale()
{
int itemcount=0,itemcode=0;
double weight=0,unitprice=0,unittotal=0;
cout<<"How many items in this sale: " ;
cin>>itemcount;
for(int i=1;i<=itemcount;i++)
{
cout<<"Item Code: ";
cin>>itemcode;
if(itemcode<100)
{
cout<<"Item price/pound: ";
cin >> unitprice;
cout<<"Item weight: ";
cin>>weight;
unitprice=unitprice*weight;
}
else
{
cout<<"Item price: ";
cin >> unitprice;
unitprice = unitprice + unitprice*0.1;
}
unittotal += unitprice;
}
cashRegister += unittotal;
salecount++;
return ;
}
int main()
{
int choice=0;
cout<<"Walgreens store Cash Register Manager"<<endl;
while(choice!=5)
{
cout<<endl;
cout<<"1- New Sale"<<endl;
cout<<"2- Cash Out"<<endl;
cout<<"3- Cash In"<<endl;
cout<<"4- Report"<<endl;
cout<<"5- Exit"<<endl;
cout<<"What do you want to do: ";
cin>>choice;
if(choice==1)
{
makeSale();
}
else if(choice==2)
{
double amount;
cout<<"Cash-out amount? ";
cin>>amount;
if(amount<cashRegister)
{
cashRegister -= amount;
}
else
cout<<"Cash out amount cannot be greater than Cash Register amount. Please retry";
}
else if(choice==3)
{
double amount;
cout<<"Cash-in amount? ";
cin>>amount;
cashRegister += amount;
}
else if(choice==4)
{
cout<<"# of sales: " << salecount << endl;
cout<<"Total: " << cashRegister << endl;
}
else if(choice==5)
{
cout<<"Thank You"<<endl;
break;
}
else
cout<<"Invalid choice Please retry"<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.