Your program needs to store the sales price of cars purchased. You are to store
ID: 3880159 • Letter: Y
Question
Your program needs to store the sales price of cars purchased. You are to store the sales price NOT THE LIST PRICE.
Your program needs to allow a user to store up to 50,000 car sales.
Once a user presses “ENTER A NEW SALE” the program will ask the following questions:
What is the sticker Price of the car you are buying
Are you a first time buyer
Are you a veteran
Are you a student
Is it the last day of the month
RULES of a car sale
If it is the last day of the month, the car is discounted by 5% before any other discounts are applied.
First buyers get a $500 credit
Veterans get a 1% discount off the final price of the car
Students get an extra $700 off the price.
Students that are also first time car buyers get the other discounts plus another $500 off the sticker price.
The program will output the following information at any time during the running of the program. The output will go to the screen.
Total cars sold
Average car sold price
Total revenue collected
Assuming the dealer marks up the final price by 5% then total revenue earned by the dealer will go up by that amount (the revenue from that sale).
RULES for your program
You need comments
Main needs to have a switch and a bunch of function calls
Main will have variables
The majority of your work with be done within functions
c program
Explanation / Answer
/*
============================================================================
Name : cars.c
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
float lastdaymonths(float p){
float disc_price=p-p*0.05;
return disc_price;
}
float firstbuyers(float p){
float new_price = p - 500;
return new_price;
}
float vaterans(float p){
float disc_price = p-p*0.01;
return disc_price;
}
float students(float p){
return p-700;
}
float first_time_student(float p){
return p-1200;
}
int main(void) {
char x='n',v = 'n',s='n',ftb='n',ldm='n'; /* x = control new sale
v = vateran check
s = student check
ftb = first time buyer check
ldm last day month check */
float sp,cp[50000],sum=0,avg=0; // sp = sticker price cp[]=store final car price
int i=0;
printf("Do You want to Enter a New Sale ? Press Y for yes or N for no: ");
scanf("%c",&x);
if(x=='Y'||x=='y'){
int c=0;
printf("What is the sticker price of car you are buying? : ");
scanf("%f",&sp);
printf("Are you a first time buyer? : ");
scanf("%c",&ftb);
printf("Are you a veteran? : ");
scanf("%c",&v);
printf("Are you a student? : ");
scanf("%c",&s);
printf("Is it last day of month? : ");
scanf("%c",&ldm); // for converting to switch case generate different case using conditions
if(ftb=='Y'||ftb=='y'){
if(s=='Y'||s=='y'){
c=1;
if(ldm=='Y'||ldm=='y'){
c=2;
}
}
if(v=='Y'||v=='y'){
c =3;
if(ldm=='Y'||ldm=='y'){
c=4;
}
}
}
else{
if(s=='Y'||s=='y'){
if(ldm=='Y'||ldm=='y'){
c=5;
}
else
c=6;
}
if(v=='Y'||v=='y'){
c =7;
if(ldm=='Y'||ldm=='y'){
c=8;
}
}
} // Apply switch case as per different conditions
switch(c){
case 1: cp[i]=first_time_student(sp);
break;
case 2: cp[i]=students(lastdaymonths(sp-500));
break;
case 3: cp[i]=vaterans(firstbuyers(sp));
break;
case 4: cp[i]=vaterans(firstbuyers(lastdaymonths(sp)));
break;
case 5: cp[i]=students(lastdaymonths(sp));
break;
case 6: cp[i]=students(sp);
break;
case 7: cp[i]=vaterans(sp);
break;
case 8: cp[i]=vaterans(lastdaymonths(sp));
break;
default: printf("Default case");
}
i++;
}
printf(" Total cars sold: %d",i+1); //print total no of cars sold
int j;
for(j=0;j<=i;j++){
sum = sum +cp[i];
}
avg = sum/(i+1);
printf("Average car sold price : %f",avg);
printf(" total revenue earned %f",sum+sum*0.05);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.