Question: Write a program to compute some statistics on the cost of operating the above car each time you fill up with gas. Your program should

Write a program to compute some statistics on the cost of operating the above car each time you fill up with gas. Your program should prompt the user for the number of gallons used and the number of miles since the last fill up. It should print the number of gallons, the cost per gallon ($3.12 - only the best :-)), the cost of the fill-up, cost per mile, and miles per gallon for the fill-up. Use the five step process to develop this program including a hand example to get some sample data, write the algorithm (and use the steps as comments in your code), and then code and test your program.

/* File : cars.c * * By : * * login: * * team : * * Date : */ /* A program to compute the cost of a new Porsche */ main() { /* program constants */ float discount_rate = 0.12; float luxury_tax_base = 30000.00; float luxury_tax_rate = 0.10; float sales_tax_rate = 0.0417; float sticker_price; /* sticker price of the car */ float discount_price; /* discounted price of item */ float taxes; /* tax is luxury tax + sales tax */ float final_cost; /* cost including sales tax */ /* Get sticker price */ printf("Enter sticker price: "); scanf("%f", &sticker_price); /* Compute discount price */ discount_price = (sticker_price - (sticker_price * discount_rate)); /* Compute taxes */ taxes = (((discount_price - luxury_tax_base) * luxury_tax_rate) + (discount_price * sales_tax_rate)); /* Compute final cost */ final_cost = (discount_price + taxes); /* Output results */ printf("Sticker price:\t\t\t\t\t%8.2f ", sticker_price); printf("Price after %.1f%% discount:\t\t\t%8.2f ", discount_rate * 100, discount_price); printf("Taxes (luxury and sales):\t\t\t%8.2f ", taxes); printf("Total cost:\t\t\t\t\t%8.2f ", final_cost); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!