Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago