Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed
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 M): ". M stands for metrie (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 . ", and end the program (do NOT ask the user for a new input). 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 %.21 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 IMPH = 1.61 KPH, 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 (b) Input: 88.52 M; Output: 54.88 I (c) Input: 100 i; Output: The unit nust be either I or M Note: In this program, you must use a svitch statement. Include all of your code in one file named speed.c

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions