Answer to Question #199724 in C++ for jay

Question #199724

Write a program that implements unit conversion for the following pairs: (1) lbs -> kg, (2) miles -> km and (3) Fahrenheit -> Celsius. Each conversion should be implemented using a function with has no return value. The main program will ask the user for a number to indicate which conversion they want to perform. Within the body of each of the function the user will then be prompted for the value to be converted. The result of the conversion should be displayed within the function.



1
Expert's answer
2021-05-27T19:08:05-0400


#include <iostream>


using namespace std;
void lbsTOkg(double n){
    cout<<n<<" lbs is eqivalent to "<<n*0.45359237<<" kg"<<endl;
}
void milesTOkm(double n2){
    cout<<n2<<" miles is eqivalent to "<<n2*1.609344<<" km"<<endl;
}
void FahrenheitToCelsius(double n3){
    cout<<n3<<" Fahrenheit is eqivalent to "<<(n3-32)*(5/9.0)<<" Celsius"<<endl;
}
int main()
{
    int ch;
    cout<<"\n1. lbs to kg ";
    cout<<"\n2. miles to km ";
    cout<<"\n3. Fahrenheit to Celsius ";
    cout<<"\nEnter your choice: ";
    cin>>ch;
    double num;
    cout<<"\nEnter the number to be converted: ";
    cin>>num;
    
    switch(ch){
        case 1:
            lbsTOkg(num);
            break;
        case 2:
            milesTOkm(num);
            break;
        case 3:
            FahrenheitToCelsius(num);
            break;
        default:
            cout<<"\nInvalid Input";
            break;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog