Question: I have written a code in c# that asks a user to enter their name, destination, miles driven and gallons used and returns a mpg

I have written a code in c# that asks a user to enter their name, destination, miles driven and gallons used and returns a mpg value. I need to have to have runtime errors shown with one of these conditions with each new run. 1. A missing input value, when prompted just hit enter. 2. Received a string, expected a double. 3. Received a double expected an int. 4. received a double expected an string. 5. when asked for gallons used enter 0. The issue is I cant seem to get these errors to appear or if they do they all seem similar?

Console.WriteLine("Please enter name"); string Name = Console.ReadLine(); Console.WriteLine("Please enter destination"); string Destination = Console.ReadLine(); Console.WriteLine("Enter the number of miles driven (whole numbers please): "); int milesDriven = int.Parse(Console.ReadLine());

Console.WriteLine("Enter the number of gallons used (whole numbers please): "); float gallonsUsed = float.Parse(Console.ReadLine());

float mpg = milesDriven / gallonsUsed; if (mpg > 30) { Console.WriteLine($"{Name}, the trip to {Destination} was very economical."); Console.WriteLine($"You drove {milesDriven} miles using {gallonsUsed} gallons."); Console.WriteLine($"The fuel efficiency of this trip was {mpg} miles per gallon."); Console.WriteLine($"With a MPG of over 30 the trip was good in cost efficiency."); } else if (mpg >=21 && mpg <= 30) { Console.WriteLine($"{Name}, the trip to {Destination} was economical."); Console.WriteLine($"You drove {milesDriven} miles using {gallonsUsed} gallons."); Console.WriteLine($"The fuel efficiency of this trip was {mpg} miles per gallon."); Console.WriteLine($"With a MPG close to 30 the trip was average in cost efficiency."); } else if (mpg <= 20) { Console.WriteLine($"{Name}, the trip to {Destination} was not economical."); Console.WriteLine($"You drove {milesDriven} miles using {gallonsUsed} gallons."); Console.WriteLine($"The fuel efficiency of this trip was {mpg} miles per gallon."); Console.WriteLine($"With a MPG of under 20 the trip was poor in cost efficiency."); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!