Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and

Write a C++ program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and a choice of whether that number is in miles to be converted to kilo- meters or kilometers to be converted to miles. Each conversion is done with a value returning function. You may use the following conversions.

1 kilometer = .621 miles

1 mile = 1.61 kilometers

I have created the following code but i am struggling to call the functions and having the program actually work

#include "pch.h" #include

using namespace std; //function miles to kilometers void convertToKilometers(float miles, float& kilometers); void convertToMiles(float kilometers, float& miles);

int main() { float miles; float kilometers; int option;

do { cout << "1. Convert miles to kilometers. " << endl; cout << "2. Conver kilometers to miles. " << endl; cout << "3. End program. " << endl; cin >> option; if (option == 1) { cout << "Enter the number of miles: " << endl; cin >> miles; kilometers = convertToKilometers(miles, kilometers); cout << miles << "equals to " << kilometers << endl; } else if (option == 2) { cout << "Enter the number of kilometers: " << endl; cin >> kilometers; convertToMiles(kilometers, miles); cout << kilometers << "equals to " << miles << endl; } else if (option == 3) { cout << "This program has been closed thank you for using it!! " << endl; }

} while (option != 3);

return 0; }

float convertToKilometers(float miles, float kilometers) { kilometers = miles * 1.61; }

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

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions

Question

Write and customize cover letters

Answered: 1 week ago

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago