Suppose you are setting up a pricing scheme for a smartphone data plan. The stan
ID: 3670893 • Letter: S
Question
Suppose you are setting up a pricing scheme for a smartphone data plan. The standard rate i $0.03 per MB of data transfer per month. However, to encourage your customers to transfer lots of (and hence make yourself filthy rich), you offer the following discounts: Note that if a customer transfers a total of 3501 MB in a given month for example, he/she should be charged at the standard rate for the first 1000 MB. He/she should be charged at a 10% discount off the standard rate for the next 2500 MB. And he/she should be charged at a 20% discount off the standard rate for the last 1 MB. Assume you have variables named dataAmt and totalCharge to store the data transfer in MB and the total monthly charge (after any discounts have been applied) in dollars, respectively Assume that dataAmt already has a value, but totalCharge does not. b. Would a switch statement be a good choice for this task? Why or why not?Explanation / Answer
Code:
#include <stdio.h>
int main()
{
int dataAmt;
float rate=0.03,totalCharge;
printf("enter the total data transfered ");
scanf("%d",&dataAmt);
if(dataAmt<=1000)
{
totalCharge = dataAmt*rate;
}
else if(dataAmt<=3500)
{
totalCharge = (dataAmt*rate);//total charge
totalCharge-=(dataAmt-1000)*rate*0.1;//10% discunt on data used above 1000MB
}
else
{
totalCharge = dataAmt*rate;
totalCharge -= 2500*rate*0.1;// 10% discount on data 1000-3500 MB
totalCharge -= (dataAmt-3500)*rate*0.2;//20%discount on data above 3500MB
}
printf("total Charge = %f ",totalCharge);
return 0;
}
Output:
b)
switch is suitable for set of values, not for range of values
as we are dealing with range of values switch is not suitable
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.