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]3 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]3 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
The process of learning by making mistakes and by trial and error is called
Anton [14]
Trial and Error learning is a method only advisable where the solution is the only important aspect for the problem at hand. Should not be used or cannot be used for specific cases where the solution is needed given in a limited number of chance or trial. By making mistakes, error, and trying out to possibilities or potential solutions, one is able to eliminate one by one possible factors / solutions to the problem until the correct solution is found.
6 0
3 years ago
Choose all items that represent characteristics of HTML:
Leya [2.2K]
Markup language

used to write web pages

contains markup tags

determines how the text is displayed
4 0
4 years ago
Read 2 more answers
Which of the following is NOT a type of cable used in wired networks?a) Unshielded coaxialb) Coaxialc) Unshielded twisted-paird)
zysi [14]

Answer:

I think it is unshielded coaxial. Not 100% sure.

Explanation:

5 0
4 years ago
The ACT science test takes___minutes.<br> A. 45<br> B. 30<br> C. 35<br> D. 60
Masja [62]

Answer:

a

Explanation:

8 0
3 years ago
Read 2 more answers
The sales of last 6 months are stored in a list,
MissTica

list1 = [12500, 35000, 12000, 40000, 55000,60000]

print(sum(list1)/len(list1))

We take the sum of all the elements in the list and divide the sum by the quantity of the elements. You can put however many elements in this list and you'll always get the average using the algorithm above.

6 0
3 years ago
Other questions:
  • On the CallCenterReport worksheet, add formulas that will summarize the issues for the department entered in cell B3. In cell B6
    13·1 answer
  • When you create an internal hyperlink, you create the link that points to the bookmark using the anchor tag with which attribute
    15·1 answer
  • Which of the following aspects of a file can you NOT set by using the Save As dialog box?
    8·1 answer
  • Mai has recently created her own e-mail account. Her father gave her permission to e-mail her friends and family but warned her
    11·2 answers
  • The function of the file server is to : 1. store data and software programs that can be used by client computers on the network.
    12·1 answer
  • In Marvel Comics, what imaginary rare metal is an important natural resource of Wakanda, the home country of Black Panther?
    15·1 answer
  • It is for employees to make mistakes that compromise the security of an organization’s computer devices and sensitive informatio
    10·2 answers
  • PLEASE HELP THIS IS DUE TODAY!! WILL MARK BRAINLIEST!!
    13·2 answers
  • Will give 5 star and mark brainleist
    14·1 answer
  • Briefly the conceptual model of effective computer based instruction for adults outlining three units (output, Process and input
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!