Question: Q2) Write a program that takes a speed in miles-per-hour (MPH) or kilometers-per-hour (KPH) from standard input, converts it from one scale to the other,

 Q2) Write a program that takes a speed in miles-per-hour (MPH)

or kilometers-per-hour (KPH) from standard input, converts it from one scale to

Q2) Write a program that takes a speed in miles-per-hour (MPH) or kilometers-per-hour (KPH) from standard input, converts it from one scale to the other, and then prints the result to standard output At the start of the program, prompt the user to input a speed by printing the string "Convert speed. Input SPEED UNIT(I/M): ". M stands for metric (kilometers-per-hour) and I stands for Imperial (miles-per-hour). If the user inputs an invalid unit, then print "The unit must be either 'M' or 'I'n", and end the program (do NOT ask again). For the purposes of this program, assume that lowercase 'i' and 'm' are invalid units. If the user inputs the speed in miles-per-hour 'I'), then convert it and display the speed in kilometers-per-hour; if the user inputs the speed in kilometers-per-hour 'M'), then convert it and display the speed in miles-per-hour. Use format %.2f for your numerical output. As part of your program, you must make two functions: one that converts MPH to KPH and one that converts KPH to MPH. Consider 1MPH1.61KPH, and 1KPH-.62MPH. You can use the following function prototypes: float mph2kph (float mph); float kph2mph (float kph); Example input/output pairs (excluding the prompt) are provided below (a) Input: 65 I; Output: 104.65 M

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!