Respuesta :
Answer:
#include<iostream>
using namespace std;
//function to calculate cost of package A
float calculateA(int u){
float value=19.99;
if(u>20)
value=value+(u-20)*0.25;
return value;
}
//function to calculate cost of package A
float calculateB(int u){
float value=39.99;
if(u>100)
value=value+(u-100)*0.10;
return value;
}
void calculate(char p,int u){
float result;
//if package is A call the calculateA function to get the result
//if package is B call caculateB function to get the result
//if package is c,then set result=59.99
if(p=='A' ||p=='a'){
result=calculateA(u);
cout<<"The charges are $"<<result<<"\n";
if(calculateB(u)<result)
cout<<"By switching to Package B you would save $"<<result-calculateB(u)<<"\n";
if(59.99<result)
cout<<"By switching to Package C you would save $"<<result-59.99<<"\n";
}else if(p=='B'|| p=='b'){
result=calculateB(u);
cout<<"The charges are $"<<result<<"\n";
if(59.99<result)
cout<<"By switching to Package C you would save $"<<result-59.99<<"\n";
}else{
result=59.99;
cout<<"The charges are $"<<result<<"\n";
}
}
//main method
int main(){
char choice;
while(1){
char package;
int units;
//loop to get package name
while(1){
cout<<"Which package are you shopping for? (enter A, B, C)? ";
cin>>package;
if(package=='A' || package=='a' || package=='B' || package=='b' || package=='C' ||package=='c')
break;
cout<<"\nEnter only A, B, or C.\n";
}
//loop to get no of units
while(1){
cout<<"How many message units(1 - 672)? ";
cin>>units;
if(units>=1 && units<=672)
break;
cout<<"\nPlease enter a number between 1 and 672 inclusive\n";
}
//caling funtion to calculate cost
calculate(package,units);
cout<<"\nDo you want to go again (y/n)? ";
cin>>choice;
if(choice=='N' || choice=='n')
break;
}
cout<<"\nThank you for using this program. Goodbye.";
return 0;
}
Explanation: