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(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' . ", 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 %.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 1MPH = 1.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 (b) Input: 88.52 M; Output: 54.88 I (c) Input: 100 i; Output: The unit must be either 'I' or 'M'. Note: In this program, you must use a switch 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 to Expert-Tailored 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

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago