Module Module1 Sub Main() \'Program that prints miles per gallon Dim totalMiles
ID: 3617412 • Letter: M
Question
Module Module1
Sub Main()
'Program that prints miles per gallon
Dim totalMiles AsDouble 'sum of miles
Dim totalGallonsAs Double 'sum ofgallons
Dim tankfulCounter'number of tankfuls
'function main begins program execution
Int(Main())
'initialization phase
miles = 0
total_Miles = 0
doubleGallons = 0
double total_gallons=0.0
'repeated loop until miles equal to -1
While (miles = -1)
End While
'prompt user for data
Console.WriteLine("Enter the miles or -1 toquit : ")
Console.ReadLine(miles = -1) 'read data fromuser
Console.WriteLine("Enter the gallons or - toquit : ")
Console.ReadLine(gallons = -1)'readdata from user
'check for valid miles
If (milesdriven1 = -1)Then
enter(gallons)
'calculation and output Miles per gallon
total_miles = total_miles + mile
total_gallons = total_gallons +gallons
Console.WriteLine("MPG this tankful -") 'miles/gallons
Console.WriteLine(totalGallonsMPG-") 'total miles/total gallons
End If
End While
End Sub
End Module
Explanation / Answer
please rate-thanks your problem was the gallonsCounter logic only fixed, and not checked as per message Module miles1 Sub Main() 'Program that prints miles per gallon Dim totalMiles AsString 'total miles for trip Dim totalGallons AsString 'total gallons for trip Dim milePerGallon AsString 'miles per gallon for tankful Dim totalMilesPerGallon AsString 'miles per gallon for trip 'initialization phase float Miles = 0 float(total_miles = 0) float(totalAverage) double gallons = 0 gallonsCounter=0 double total_gallons= 0.0 'get gallons used for first tank Print("Enter miles(-1 to end): ") scan("%f", &gallons ) 'loop until sentinel value read from user While gallons -1.0 totalGallons +=gallons 'add current tank gallons to total gallonsCounter+=1 'add 1 to gallonsCounter Print("Enter the miles driven:") 'get miles driven scanf("%if", &miles): totalMiles +=miles 'add current tank miles to total 'display miles per gallon for currenttank print("the miles/gallon for this tank was%f/n/n" miles/gallons) 'get next tank's gallons Print("Enter the gallons used (-1 to end): ") scanf("%if", &gallons): End While 'calculation average miles per gallon over all tanks totalAverage = totalMiles / gallonsCounter Print(" the overall average Miles/gallon was %f ",totalAverage) Return 0 'indicate successful termination End Sub End ModuleRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.