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...

  • 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!

  • This is a basic java program where you convert units using only loops, control statements and...

    This is a basic java program where you convert units using only loops, control statements and format modifiers: Create a Java program named UnitConversion.java that converts the following: 1. Liter to gallon 2. Gallon to liter 3. Kilometers to miles 4. Miles to kilometers The conversion formulas: 1 liter = 0.264172 gallon 1 gallon = 3.78541 liters 1 kilometer = 0.621 miles I mile = 1.609 kilometers

  • In Visual Basics - Program 2. Mileage Write a program which allows the user to enter...

    In Visual Basics - Program 2. Mileage Write a program which allows the user to enter the distance they have traveled by car in miles and the number of gallons of gasoline they used to travel the distance. Be sure to allow for decimal places for both values. Your results should show miles per gallon and kilometers per gallon. A kilometer is 0.61 miles, and this value must be stored as a constant. Your outputs must be formatted to 2...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

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
ADVERTISEMENT