Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several trips by recording miles driven and gallons used for each trip. Develop a C++ program that uses a while statement to input the miles driven and gallons used for each trip. The program should calculate and display the miles per gallon obtained for each trip and print the combined miles per gallon obtained for all tankfuls up to this point.

a) Read the problem statement.
b) Formulate the algorithm using pseudocode and top-down, stepwise refinement.
c) Write a C++ program.
d) Test, debug and execute the C++ program.
```
Enter miles driven (-1 to quit): 287
Enter gallons used: 13
MPG this trip: 22.076923
Total MPG: 22.076923
Enter miles driven (-1 to quit): 200
Enter gallons used: 10
MPG this trip: 20.000000
Total MPG: 21.173913
Enter the miles driven (-1 to quit): 120
Enter gallons used: 5
MPG this trip: 24.000000
Total MPG: 21.678571
Enter the miles used (-1 to quit): -1
```


Top:
Determine if each of an arbitrary number of department store customers has exceeded the credit limit on a charge account
First refinement:
Input customer’s data
For each customer, calculate and display the customer’s new balance, and display a message if user’s balance exceeds credit limit
Process next customer
Second refinement:
Prompt the user for the first customer’s account number
Input the first customer’s account number
While the sentinel value (-1) has not been entered for the account number
Prompt the user for the customer’s beginning balance
Input the customer’s beginning balance
Prompt the user for the customer’s total charges
Input the customer’s total charges
Prompt the user for the customer’s total credits
Input the customer’s total credits
Prompt the user for the customer’s credit limit
Input the customer’s credit limit
Calculate and display the customer’s new balance
If the balance exceeds the credit limit
Print the account number
Print the credit limit
Print the balance
Print “Credit Limit Exceeded”
Input the next customer’s account number

Computer Science & Information Technology

You might also like to view...

To assign a double variable d to a float variable x, you write

a. x = (long)d b. x = (int)d; c. x = d; d. x = (float)d;

Computer Science & Information Technology

An employee's ID number, name, company position, address, city, state, and Zip Code make up a record

Indicate whether the statement is true or false

Computer Science & Information Technology

The binary numbering system uses only two symbols-the digits 0 and 1-to represent all possible numbers.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Math.pow(4, 1 / 2) returns __________.

a. 2 b. 2.0 c. 0 d. 1.0 e. 1

Computer Science & Information Technology