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.
#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;
}
Comments
Leave a comment