Can someone help me out with this C Program Writting Please

Can someone help me out with this C++ Program Writting Please

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful\'s of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankful\'s.

Output

Enter the gallons used (-1 to end): 16

Enter the miles driven: 220

The Miles / Gallon for this tank was 13.75

Enter the gallons used (-1 to end): 16.5

Enter the miles driven: 272

The Miles / Gallon for this tank was 16.4848

Enter the gallons used (-1 to end): -1

The overall average Miles/Gallon was 15.1385

Notes

Can you give me program FULL DOCUMENTATION or COMMENTS.

Use meaningful prompt don\'t let the user to guess what to input to your program.

Solution

#include<stdio.h>

int main(void)

{

/*Initialize all the variables to zero*/

float gallons, miles, totalGallons = 0.0;

float totalAverage = 0.0;

float totalMiles = 0.0;

printf (\"Enter gallons used (-1 to end): \");

scanf (\"%f\", &gallons);

while (gallons != -1)

{

totalGallons += gallons;

printf (\"Enter number of miles driven: \");

scanf (\"%f\",&miles);

totalMiles += miles;

printf (\"The miles per gallon for this tank was %f\", miles/gallons);

printf (\"\ Enter the gallons used (-1 to end):\");

scanf (\"%f\", &gallons);

}

if (totalGallons != 0)

{

/* Calculate total average as totalMiles/totalGallons*/

totalAverage = totalMiles/totalGallons;

printf (\"\ The overall average miles per gallon was %f \ \", totalAverage);

}

else

printf (\"No gallons were entered\ \");

return 0;

}

Can someone help me out with this C++ Program Writting Please Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of
Can someone help me out with this C++ Program Writting Please Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site