Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gas- oline by recording miles driven and gallons used for each tankful. Develop a JavaScript program that will input the miles driven and gallons used (both as integers) for each tankful. The program should calculate and output HTML text that displays the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point. Use prompt dialogs to obtain the data from the user.
What will be an ideal response?
Top:
Determine the average miles/gallon for each tank of gas, and the overall miles/gallon for an arbitrary number of tanks of
gas.
First refinement:
Initialize variables
Input the gallons used and the miles driven, calculate and print the miles/gallon for each tank of gas, and calculate and
print the overall average miles/gallon. Keep track of the total miles and the total gallons.
Second refinement:
Initialize totalGallons to zero
Initialize totalMiles to zero
Read the miles driven for the first tank
While the sentinel has not been entered
Add miles to the running total in totalMiles
Get the gallons used for the current tank
Add miles to the running total in totalGallons
Calculate the miles/gallon
Calculate the total miles/gallon
Display the miles per gallon for this tank full and total miles per gallon
Read the miles driven for the next tank
```
1
2
3
4
5
6
7
You might also like to view...
Proper risk assessment requires the organization to have a sufficiently focused, organization-wide process in place to conduct threat identification and risk ____.
A. evaluations B. management C. avoidance D. acceptance
What are the characteristics of complex software systems that make reductionism a less effective approach for software engineering?
What will be an ideal response?
Entering a positive value in the Set rotation text box rotates artwork in a clockwise direction.
Answer the following statement true (T) or false (F)
To open the Preferences dialog box in Windows, click ____ on the Menu bar, point to Preferences, and then click a preference category to open the dialog box.
A. File B. Window C. Edit D. Options