Question

Write a program that will convert miles to kilomet
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <iomanip>
using namespace std;

//Function declaration
double milesToKilometers(double miles);
double kilometersToMIles(double kms);

//This function will convert miles to kilometers
double milesToKilometers(double miles)
{
   //calculating the no of miles and returning it
   return miles*1.61;  
}

//This function will convert kilometers to miles
double kilometersToMIles(double kms)
{
   //calculating the no of kilometers and returning it
   return kms*0.621;
}
int main()
{
   //Declaring variables
   int choice;
double miles,kilometers;

//This loop continues to execute until user enters '3'
do
{
//Displaying menu
cout<<"\n\nPlease Input"<<endl;
cout<<"\t1.Convert Miles to Kilometers"<<endl;
cout<<"\t2.Convert Kilometers to Miles"<<endl;
cout<<"\t3.Quit\n"<<endl;

//Getting the user choice entered by the user
cin>>choice;
switch(choice)
{
   /* If the user selected choice 1
   * then this case 1 will get executed
   */
   case 1:
       {
           //Getting the miles entered by the user
       cout<<"Please input Miles to be converted :";
       cin>>miles;
         
       //calling the function milesToKilometers by passing miles as input
cout<<miles<<" Miles= "<<std::fixed<< std::setprecision(2)<<milesToKilometers(miles)<<" Kilometers.";
break;
       }
       case 2:
       {
           //Getting the kilometers entered by the user
cout<<"Please input Kilometers to be converted :";
       cin>>kilometers;
         
          //calling the function kilometersToMiles by passing kilometers as input
cout<<kilometers<<" Kilometers= "<<std::fixed<< std::setprecision(2)<<kilometersToMIles(kilometers)<<" Miles.";          
           break;
       }
      
}
}while(choice!=3);
     
return 0;
}

____________________________________________

Output:

Add a comment
Know the answer?
Add Answer to:
Write a program that will convert miles to kilometers and kilometers to miles. The user will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB - create MATLAB functions to convert kilometers to miles and vice versa according to the...

    MATLAB - create MATLAB functions to convert kilometers to miles and vice versa according to the following conditions. (a) The functions created will have input of miles or kilometers and the output with converted kilometers or miles. (b) The output of the function should be a conversion table. No input for the function is needed. (1 mile = 1 609.344 meter) - function with the following: (1) output a third-order polynomial function with the coefficients as the input variables; (2)...

  • You want to write a converter program which will let user convert distance and weight from SI to ...

    Use functions to complete this C + + program You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want...

  • Write a C++ program that shows the following menu options and lets the user to convert...

    Write a C++ program that shows the following menu options and lets the user to convert from Metric to Imperial system: Converter Toolkit --------------------     1. Temperature Converter     2. Distance Converter     3. Weight Converter     4. Quit If the user enters 1, the program should ask for the temperature in Celsius and convert it to Fahrenheit If the user enters 2, the program should ask for the distance in Kilometer and convert it to Mile If the user...

  • GUI Programming Creating a Kilometer to Miles Converter Lab Assignment Objectives Understand the basics of tkinter...

    GUI Programming Creating a Kilometer to Miles Converter Lab Assignment Objectives Understand the basics of tkinter GUI development. Based on an informal application specification be able to develop a tkinter GUI program that contains one or more Label widgets. Be able to prompt user for input to a GUI application using a messagebox. Obtain user input into a GUI application that can be used for event driven selection. Be able to develop a tkinter GUI program that supports event-based widgets....

  • Write a C++ program that will convert distance measurements from miles to kilometers. Specifically, the program...

    Write a C++ program that will convert distance measurements from miles to kilometers. Specifically, the program needs to convert 0, 10, 20, 30, 40 , 50, 60, 70, 80, and 90 miles to kilograms displaying both the number of miles and the number of kilograms on the same line. please comment on what is pre and post condition too

  • java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for...

    java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for to solve the following problem about converting between Kilometers to Miles. Sample Run is shown below You are asked to implement only the menu item under Formulas which reads as"KM to Mile". Choosing this menu item will display the following input box: Input Enter Kilometers Value OK Cancel The result will be displayed in a TextArea as shown below: JavaF× Menu Example " File...

  • #function to covert kilometer to miles #takes km input as an argument and return the calculation...

    #function to covert kilometer to miles #takes km input as an argument and return the calculation def kilometer_to_miles(km): return km * 0.6214 #function to covert miles to kilometer #takes miles input as an argument and return the calculation def miles_to_kilometer(miles): return miles/0.6214 #Main function to find the distance #by calling either of the two functions #prompt the user to enter his/her choice of distance conversion restart = 0 while (restart == 'y'): user_input = input ("Enter k to convert kilometer...

  • Python code please!! Provide code and screenshots to both code and its output!!! Write a program...

    Python code please!! Provide code and screenshots to both code and its output!!! Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done as...

  • k2m.cpp Write a program which converts kilometers to miles and miles to kilometers. Input value (m...

    k2m.cpp Write a program which converts kilometers to miles and miles to kilometers. Input value (m or km)is in argv[1] Program is accessed by "k2m" or "m2k", using Unix' ability to assign SYMBOLIC LINKS to files, so they have multiple names. The program knows to do kilometers -> or miles -> km by examining its name in argv[0]. (It does a string comparison on argv[0]). Miles to kilometers: m2k Kilometers to miles: k2m If you're developing on a Windows machine...

  • plesse help! Kilometer Converter Design a modular program that asks the user to then converts that...

    plesse help! Kilometer Converter Design a modular program that asks the user to then converts that distance to miles. The conversion formula is as follows: enter a distance in kilometers, and Miles = Kilometers x 0.6214 THANKS!

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT