Question 764734: 1-7 Jake's Problem.
Jake has a car with an 8-gallon fuel tank. Jake fills his tank with gas and then drives 60 miles to a friend's house. When he gets to his friend's house, he has 6 gallons left in his fuel tank. Write a program that uses three input elements to enter values for tank size, miles traveled and gallons left. The program should calculate and display how many miles Jake can drive on a full tank of gas. (Note: Be sure to use input elements to accept the values 8, 60, and 6 rather than hard coding them into your solution. Also be sure your output is descriptive and avoid doing multiple expressions within one assignment statement, keep it simple! )
Answer by josgarithmetic(39613) (Show Source):
You can put this solution on YOUR website! Let's look at the arithmetic first, using variables.
c = gallons capacity of the fuel tank
r = gallons of fuel remaining after a trip when started with a full tank
d = miles distance traveled when r remains in the tank.
Your example problem uses c=8, r=6, d=60.
The question asks, how many miles is equivalent to a full tank filled with c gallons.
Find the expression for how many gallons used in the trip.
will be gallons used for d miles.
There is a ratio of miles per gallon.
A trip would have been d miles to use gallons. You use this ratio applied to the tank capacity to find how many miles a full tank will allow.
Let D = MILES for a full tank filled at capacity c.
D is your output variable.
The formula for D is this:

OR
As a review, this is how you may analyze your variables.
INPUT VARIABLES
c = volume of fuel tank capacity in gallons
r = volume remaining in tank after a trip when started at full capacity
d = miles gone corresponding to r
OUTPUT VARIABLE
D = MILES how far the tank filled at capacity c can allow car to travel
and not that .
You can easily write a simple BASIC program to handle that information. A few small refinements will make such a simple program easy to use and neat to run. You could do a single straight run-through, or you can arrange a loop. Best on the tutoring side, to not do the whole program for you, but the needed program is simple enough: Write the necessary INPUT statements for c, r, and d, and then write the code to compute result and display the resulting information display.
.... a few additional comments...
For program looping, you might want a CLS statement or some 'clear screen' command to refresh the display before asking for a new set of input data.
You could want some code for input-mistake checking and to handle user-given input mistakes.
You did not say if your BASIC system requires line numbers or not.
|
|
|