Computers and Technology

Driving costs (with pointers)
Complete the program below using pointers.

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

Output each floating-point value with two digits after the decimal point, which can be achieved by executing
cout << fixed << setprecision(2); once before all other cout statements. This line is included for you.

Ex: If the input is:

20.0 3.1599
the output is:

3.16 11.85 79.00
Note: Real per-mile cost would also include maintenance and depreciation.

#include
#include
using namespace std;

int main() {

/* Update the declarations below so that each variable points to a
* double on the heap.
*/

double *milesPerGallon;
double *dollarsPerGallon;
double *dollars20Miles;
double *dollars75Miles;
double *dollars500Miles;

/* Write the statements here to:
* 1) Read a value from the keyboard into the variable pointed to by
* milesPerGallon.
* 2) Read a value from the keyboard into the variable pointed to by
* dollarsPerGallon.
*/

/* Write the appropriate statements here to:
* 1) Assign the proper calculated value to the variable pointed to by
* dollars20Miles.
* 2) Assign the proper calculated value to the variable pointed to by
* dollars75Miles.
* 3) Assign the proper calculated value to the variable pointed to by
* dollars500Miles.
*/

cout << fixed << setprecision(2);

cout << *dollars20Miles << " " << *dollars75Miles << " " << *dollars500Miles << endl;

return 0;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, Siebee23
This program will store roster and rating information for a soccer team. coaches rate players during tryouts to ensure a balanced team. (1) prompt the user to input five pairs of numbers: a player's jersey number (0 - 99) and the player's rating (1 - 9). store the jersey numbers in one int vector and the ratings in another int vector. output these vectors (i. e., output the roster). (3 pts) ex: enter player 1's jersey number: 84 enter player 1's rating: 7 enter player 2's jersey number: 23 enter player 2's rating: 4 enter player 3's jersey number: 4 enter player 3's rating: 5 enter player 4's jersey number: 30 enter player 4's rating: 2
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, juandguardado7045
Your company has 1,500 desktop computers running windows 7. you want to upgrade them to windows 10. which type of microsoft license would be best suited in this situation?
Answers: 3
image
Computers and Technology, 22.06.2019 18:30, smariedegray
All of the following are characteristics that must be contained in any knowledge representation scheme except
Answers: 3
image
Computers and Technology, 22.06.2019 23:30, ansonhunter8891
What are listed in the vertical columns across the top of the event editor? a. file names b. conditions c. check marks d. action types
Answers: 1
Do you know the correct answer?
Driving costs (with pointers)
Complete the program below using pointers.

Driving i...

Questions in other subjects: