Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Input miles input gallons prompt for miles get miles prompt for gallon get gallo

ID: 3655216 • Letter: I

Question

Input miles input gallons prompt for miles get miles prompt for gallon get gallons calculate miles per gallon calculate overall miles per gallon write miles per gallon write overall miles per gallon Need to use sentinel value -1 to stop program when all data has been added. Here is my coding and it does not work using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int miles; int gallons; miles = 0; gallons = 0; int mpg; mpg = 0; int totalMiles; int totalGallons; totalMiles = 0; totalGallons = 0; int tripCounter; tripCounter = 0; int ompg; ompg = 0; { Console.Write("Enter miles in this tank:"); Convert.ToInt32(Console.ReadLine()); Console.Write("Enter gallons in this tank:"); Convert.ToInt32(Console.ReadLine()); while (miles != -1) { mpg = miles / gallons; totalMiles = totalMiles + miles; totalGallons = totalGallons + gallons; tripCounter = tripCounter + 1; Console.Write(" Miles per Gallons: "); Convert.ToInt32(Console.ReadLine()); if (tripCounter > 0) { ompg = totalMiles / totalGallons; Console.WriteLine("Write overall miles per gallons:"); Convert.ToInt32(Console.ReadLine()); } else { Console.WriteLine("No trips taken:"); Console.ReadLine(); } } } } } }

Explanation / Answer

#include int main(void) { /*Initialize all the variables to zero*/ float gallons, miles, totalGallons = 0.0; float totalAverage = 0.0; float totalMiles = 0.0; /* Prompt the user for number of gallons (user will enter –1 to end entries)*/ printf ("Enter gallons used (-1 to end): "); scanf ("%f", &gallons); /* While the number of gallons is not -1*/ while (gallons != -1) { /* Add number of gallons to totalGallons */ totalGallons += gallons; /* Prompt user to enter number of miles driven */ printf ("Enter number of miles driven: "); scanf ("%f",&miles); /*Add number of miles driven to total number of miles driven*/ totalMiles += miles; /* Calculate and print miles per gallon for current tank */ printf ("The miles per gallon for this tank was %f", miles/gallons); /* Prompt user for number of gallons */ printf (" Enter the gallons used (-1 to end):"); scanf ("%f", &gallons); } /* If totalGallons is not zero*/ if (totalGallons != 0) { /* Calculate total average as totalMiles/totalGallons*/ totalAverage = totalMiles/totalGallons; /*Print totalAverage to screen*/ printf (" The overall average miles per gallon was %f ", totalAverage); } else /* If no gallons entered give error message to user*/ printf ("No gallons were entered "); return 0; }