Khalid A.
asked 11/04/14Programming questions
this question is stressing me out i cant even know what to start. it is in Visual Basic. Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speed limit and the driver's speed. Validate the input as follows:
-The speed limit should be at lease 20, but not greater than 70.
-The driver's speed should be at least the value entered for the speed limit (otherwise the driver was not speeding).
Once correct data has been entered, the program should calculate and display the number of miles per hour over the speed limit that the driver was doing.
-The speed limit should be at lease 20, but not greater than 70.
-The driver's speed should be at least the value entered for the speed limit (otherwise the driver was not speeding).
Once correct data has been entered, the program should calculate and display the number of miles per hour over the speed limit that the driver was doing.
More
1 Expert Answer
Steven M. answered 03/01/17
Tutor
5
(5,792)
17,500+ Wyzant Hours Taught | Berkeley Grad | Classroom Experience!
You should only be prompting once for the speed limit (or repeatedly if you get bad data), and once for the user's current speed. I'd use the actual numbers to determine if it's valid data or not, rather than a string set to "yes" or "no". Try picking it up from here:
Module Module1
Sub Main()
Console.WriteLine("Please enter speed limit, if it's between 19 and 71 mph, then press enter")
Dim speed_limit As Integer
Sub Main()
Console.WriteLine("Please enter speed limit, if it's between 19 and 71 mph, then press enter")
Dim speed_limit As Integer
speed_limit = Integer.Parse(Console.ReadLine())
Console.WriteLine("You entered:" & speed_limit)
Console.WriteLine("You entered:" & speed_limit)
While speed_limit < 20 Or speed_limit > 70
If speed_limit < 20 Then
message = "Sorry, speed limit less than 20 mph. Try again "
ElseIf speed_limit > 70 Then
message = "Sorry, speed limit more than 70 mph.Try again."
End If
message = "Sorry, speed limit less than 20 mph. Try again "
ElseIf speed_limit > 70 Then
message = "Sorry, speed limit more than 70 mph.Try again."
End If
Console.WriteLine(message)
speed_limit = Integer.Parse(Console.ReadLine())
End While
End While
Console.WriteLine("How fast are you driving?")
Dim car_speed As Integer
car_speed = Integer.Parse(Console.ReadLine())
If car_speed > valid_speed_limit Then
message = "Alert! You are driving over the speed limit"
Else
If car_speed > valid_speed_limit Then
message = "Alert! You are driving over the speed limit"
Else
message = "You are driving at or under the speed limit."
EndIf
Console.WriteLine(message)
End Sub
End Module
EndIf
Console.WriteLine(message)
End Sub
End Module
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Anthony F.
11/02/15