1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alexgriva [62]
4 years ago
9

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the g

as cost for 10 miles, 50 miles, and 400 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.2of", your Value);
Computers and Technology
2 answers:
pickupchik [31]4 years ago
8 0

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

  gallon_used = driven_miles / miles_per_gallon

  cost = gallon_used * dollars_per_gallon  

  return cost  

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Explanation:

Allisa [31]4 years ago
6 0

Answer:

The C program is given below.

#include<stdio.h>

int main() {

   double speed, gas_cost, cost_1, cost_10, cost_50, cost_400;    

   printf("Enter car's speed in miles/gallon  ");

   scanf("%lf", &speed);    

   printf("Enter cost of gas in dollars/gallon  ");

   scanf("%lf", &gas_cost);    

   // fraction gives the gallons of gas needed for 1 mile.

   // gallons of gas needed for 1 mile * cost of 1 gallon of gas = gas cost for 1 mile

   cost_1 = (1/speed)*gas_cost ;    

   // cost of gas for 10 miles

   cost_10 = cost_1 * 10;

   printf("Cost of gas for 10 miles in dollars is  ");

   printf( "%0.2f", cost_10 );

   printf("\n");    

   // cost of gas for 50 miles

   cost_50 = cost_1 * 50;

   printf("Cost of gas for 50 in dollars miles is  ");

   printf( "%0.2f", cost_50 );

   printf("\n");    

   // cost of gas for 400 miles

   cost_400 = cost_1 * 400;

   printf("Cost of gas for 400 in dollars miles is  ");

   printf( "%0.2f", cost_400 );

   printf("\n");    

   return 0;

}

OUTPUT

Enter car's speed in miles/gallon  20                                                                                          

Enter cost of gas in dollars/gallon  30                                                                                        

Cost of gas for 10 miles in dollars is  15.00                                                                                  

Cost of gas for 50 in dollars miles is  75.00                                                                                  

Cost of gas for 400 in dollars miles is  600.00  

Explanation:

This program takes user input for cost of gas in dollars and speed of the car in miles per gallon.

Next, gallons needed for 1 mile is calculated.  

cost_1 = (1/speed)*gas_cost ;

Following this, gallons needed for 10 miles, 50 miles and 400 miles are calculated.

cost_10 = cost_1 * 10;

cost_50 = cost_1 * 50;

cost_400 = cost_1 * 400;

These values are displayed on the screen with two decimal places by using printf( "%0.2f", your_value).

All the variables needed in this program are declared as double.

All the instructions mentioned have been implemented. This program can be tested for all possible positive numbers.

You might be interested in
Alicia would like to make important text in her spreadsheet stand out. Alicia should _____
Airida [17]
Probably bold the important text? Its hard without multiple choice
4 0
3 years ago
Read 2 more answers
All the network nodes are connected to each other
Shalnov [3]
It’s a mesh topology
7 0
3 years ago
What is the default file extension for a document created in Word 2016​
navik [9.2K]

Office Open XML (OOXML) format was introduced with Microsoft Office 2007 and became the default format of Microsoft Word ever since. Pertaining file extensions include: .docx – Word document. .docm – Word macro-enabled document; same as docx, but may contain macros and scripts.

7 0
4 years ago
The internet is an example of
DochEvi [55]
A large multi user program
6 0
3 years ago
Read 2 more answers
I am not a living being, I am a cylindrical shape that has three to eight sides. I never die. I can build anything again. What i
Setler79 [48]

Answer:

A shape

Explanation:

4 0
3 years ago
Other questions:
  • Write a function (named n_pointed_star) to make the turtle draw an n-pointed star. The function should return nothing, and accep
    10·1 answer
  • The opening of the throttle plate can be delayed as long as
    13·1 answer
  • Which option allows you to view slides on the full computer screen?
    11·1 answer
  • Describe how data center storage applications drive the development of SAN technology.
    8·1 answer
  • The Circular Flow Model includes serveral actors. Which of the following is NOT listed in the Circular Flow Model?
    12·1 answer
  • which statement is true? O A Future games will be more context oriented. OB. Future games will be more product driven. Future ga
    13·2 answers
  • Who is responsible for developing the physical background for the characters by creating buildings, landscapes, and interiors?
    14·1 answer
  • Which of the follow efficiencies would be considered unreasonable?
    13·1 answer
  • Select the correct answer.
    15·1 answer
  • Briefly explain how human thinking is mapped to artificial intelligence components
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!