Question
**C not C++** Complete the program to compute discount rate based on purchase amount and customer status, according to the following table Purchase Amount Discount
**C not C++**
Complete the program to compute discount rate based on purchase amount and customer status, according to the following table Purchase Amount Discount Rate Less than 50 0% 50 or more, less than 150 10% 150 or more, less than 500 15% 500 or more, less than 1000 20% 1000 or more 25% Any customer who is a special customer and is receiving a discount of 20% or more gets an additional 2% discount For example, a special customer who makes a $300 purchase receives a 15% discount. A special customer who makes a $700 purchase gets 20% plus the additional 2%, for a total discount of 22%. In your program first use if..else if..else method to calculate the discount based on purchase amount. Then follow that with a single if statement with a logical operator to assign the 2% extra, if valid. Additional information: Dealing with percentages is usually done with the fractional value ( 0.05 for 5%, for example) so that calculations can be easily done. Note how the provided code multiplies the fraction by 100 in the printf( ) to get a displayable percentage value.
#include
int main( ) { double purchase = 0.0; char special_customer = 'n'; printf( "Enter purchase amount: " ); scanf( "%lf", &purchase ); printf( " Special customer? (y/n): " ); scanf( " %c", &special_customer ); printf( " " );
int purchase_amt, percentage;
float final_price;
char str[10];
printf("Enter the purchase amount: ");
scanf("%d",&purchase_amt);
if(purchase_amt < 50)
percentage = 0;
else if(purchase_amt >= 50 && purchase_amt < 150)
percentage = 10;
else if(purchase_amt >= 150 && purchase_amt < 500)
percentage = 15;
else if(purchase_amt >= 500 && purchase_amt < 1000)
percentage = 20;
else if (purchase_amt >= 1000)
percentage = 25;
if(percentage >= 20)
{
printf("The customer is recieving more than 20 percentage discount ");
printf("Is the customer Special Customer or not (yes/no) : ");
scanf("%s",str);
if(strcmp(str,"yes")==0)
{
percentage+=2;
printf("The customer is a special customer so he/she gets additional 2 percentage discount ");
}
else
printf("The customer is not a special customer ");
}
else
printf("The customer is not recieving 20 percentage discount ");
final_price = purchase_amt - purchase_amt * percentage * 0.01;
printf("The discount percentage is: %d and The final price is: %f ",percentage,final_price); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started