Question

Instructions Cuba, like much of the world uses the metric system. Write a program to input a metric value and then convert to

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have written the code in C++

==========================================================================================

#include <iostream>
using namespace std;

int main()
{
double inp, ans; //Variables for input and answer
int ch; //Choice for Menu
double mile_fac = 0.621, f_fac = 1.8, pound_fac = 2.205, gall_fac = 0.264; //Declaring all constants
char run = 'y';
do
{
cout << "\n\n1. Kilometres to Miles";
cout << "\n2. Celsius to Fahrenheit";
cout << "\n3. Kilograms to Pounds";
cout << "\n4. Litres to Gallons";
cout << "\n\nEnter option number:";
cin >> ch;
switch(ch)
{
case 1: cout<<"\nEnter Value in km:";
cin>>inp;
ans = inp * mile_fac; //miles = km * 0.621
cout<<"\n\nMiles: "<<ans;
break;
  
case 2: cout<<"\nEnter Value in Celsius:";
cin>>inp;
ans = inp * f_fac + 32; //F = 32 + 1.8 * C
cout<<"\n\nFahrenheit: "<<ans;
break;
  
case 3: cout<<"\nEnter Value in kg:";
cin>>inp;
ans = inp * pound_fac; // pounds = kg * 2.205
cout<<"\n\nPounds: "<<ans;
break;
  
case 4: cout<<"\nEnter Value in Litres:";
cin>>inp;
ans = inp * gall_fac; // gallons = litres * 0.264
cout<<"\n\nGallons: "<<ans;
break;
  
default: cout<<"\n\nINCORRECT OPTION NUMBER";
}
cout<<"\n\nDo you wish to re-run(Y/N)?:";
cin>>run;
}while(run == 'y' || run == 'Y');
return 0;
}
==========================================================================================

If you liked the answer, please upvote :D, and if you have any queries, do leave a comment. Thank you!

Add a comment
Know the answer?
Add Answer to:
Instructions Cuba, like much of the world uses the metric system. Write a program to input...
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
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
Active Questions
ADVERTISEMENT