Answer to Question #199727 in C++ for Master J

Question #199727

Write a program that implements unit conversion for the following pairs: (1) lbs -> kg, (2) miles -> 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 function the user will then be prompted for the value to be converted. The results of the conversion should be displayed within the function


1
Expert's answer
2021-05-29T01:58:26-0400
// A program for unit conversion
#include<iostream>
using namespace std;
function1() // Function for converting from lbs to Kg
{
	float a,b;
	cout<<"Enter a unit in lbs \n ";
	cin>>a;
	b=a*0.453592374495299;
	cout<<"The result is "<<b;
}
function2() // Function for converting from Miles to Kms
{
	float a,b;
	cout<<"Enter a unit in miles\n ";
	cin>>a;
	b=a*1.609;
	cout<<"The result is "<<b;
}
function3() //Function for converting from fahrenheit to degree celcius
{
	float a,b;
	cout<<"Enter a unit in fahrenheit\n ";
	cin>>a;
	b=(a-32.0) * 5.0 / 9.0;
	cout<<"The result is "<<b;
}

int main()
{
	int option;
	cout<<"1. lbs to Kg conversion \n2. Miles to Kms\n3. Fahrenheit to degree celcius";
	cout<<"\nChoose an operation\n";
	cin>>option;
	switch(option)
	{
		case 1:
		function1();
		break;
		case 2: 
		function2();
		break;
		case 3:
		function3();
		break;
		default:
		cout<<"Invalid choice";
	}	
	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