Question

Write a height conversion program that shall allow user to convert from feet and inches to meters (option 1) and vice versa (option 2). User shall be able to specify the type of conversion (a menu of two options). Display an error message if an invalid option is specified. Otherwise, the program would read in a length in feet and inches (two separate integer values like 5 and 6) and will output the equivalent length in meters (a double value) or read in a length in meters (a double value) and will output the equivalent length in feet and inches (two separate integer values and inches shall be between 0 and 11). There are 0.3048 meters in a foot, and 12 inches in a foot. For example, if 5 feet and 6 inches are entered for option 1 then the program should output 1.68 meters. On the other hand, if a value of 1.68 meters is entered for option 2 then the program should output 5 feet and 6 inches. You might need to perform casting (type conversion) and possibly rounding for this program to work properly

I have this c++ program that i have to create but i am stuck on it.

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

Code:

#include <iostream>

using namespace std;
//function to convert feet and inches to meters
void feetInchToMeters(int feet, int inch, double *meter)
{
*meter = feet*0.3048 + (0.3048/12)*inch;
}
//function to convert meters to feet and inches
void metersToFeetInch(int *feet, int *inch, double meter)
{
*feet = meter/0.3048;
*inch = (meter*39.301)-(*feet)*12;//1 meter = 39.301 inches
}

int main()
{
int feet;
int inch;
double meter;
int option;
do{
cout<<"1. Convert feet and inches to meters \n2. Convert meters to feet and inches \n3. Exit"<<endl;
cout<<"Select option :";
cin>>option;
if(option==1)
{
cout<<"Enter the value in feet (integer value) :";
cin>>feet;
cout<<"Enter the value in inches (integer value):";
cin>>inch;
feetInchToMeters(feet, inch, &meter);
cout<<feet<<" feet and "<<inch<<" inches equals to "<<meter<<" meters"<<endl<<endl;
}
else if(option==2)
{
cout<<"Enter the value in meters :";
cin>>meter;
metersToFeetInch(&feet, &inch, meter);
cout<<meter<<" meters equals to "<<feet<<" feet and "<<inch<<" inches"<<endl<<endl;
}
else if(option!=3)
{
cout<<"Invalid option entered"<<endl<<endl;
}
}while(option!=3);
}

Output:

1. Convert feet and inches to meters . Convert meters to feet and inches Select option 5 nualid option entered . Convert feet and inches to meters . Convert meters to feet and inches Select option 1 Enter the value in feet (integer value 5 Enter the value in inches Kinteger value6 feet and 6 inches equals to 1.6764 meters . Convert feet and inches to meters . Convert meters to feet and inches Select option 2 Enter the value in meters :1.68 68 meters equals to 5 feet and 6 inches . Convert feet and inches to meters . Convert meters to feet and inches . Exit elect option 3

Add a comment
Know the answer?
Add Answer to:
I have this c++ program that i have to create but i am stuck on it....
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
  • . Write a program that reads in a length in feet and inches and outputs the...

    . Write a program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches...

  • C++ programming language , I need help writing the code . Please explain if you can...

    C++ programming language , I need help writing the code . Please explain if you can . Exercise 10: Unit conversion (10 points) Write a console program that converts meters into feet and inches. The program starts by asking the user for a measurement in meters. The program should accept a floating point number. After getting the number, the program computes the number of feet and inches equal to the specified number of meters. The program outputs feet and inches...

  • Write a single C++ program that performs the following conversion (The modulus divide will help you...

    Write a single C++ program that performs the following conversion (The modulus divide will help you get the remainder as shown in class) 39 / 12 = 3 and 39 % 12 = 3, so 3 feet 3 inch(es) Height conversion 1 meter = 39 inches 12 inches = 1 foot Ask/Prompt the user to enter in the height in meters, convert and output the result in feet and inches Example 1 meters as input should produce 3 feet (foot)...

  • CSC110 EXAM06A Objects NAME: class meters2feet private double meters; public void setMeters (double m) {meters=m ;...

    CSC110 EXAM06A Objects NAME: class meters2feet private double meters; public void setMeters (double m) {meters=m ; } public double getMeters ){ return meters;} pubic double convert2feet ( ) { return (meters*3.2808) ; } NOTE: This class cannot be changed must be used as is C class meters2inches private double meters; public void setMeters (double m) {mete rs=m ; } public double getMeters () { return meters ; } pubic double convert2inches ( ) { return (meters*39.3701) ; NOTE: This class...

  • I am using C++ Start with the distance.cpp file on the website. Fill in the missing...

    I am using C++ Start with the distance.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find determine which entered distance is larger. The user can either enter it in meters labeled with an “m”, or in feet and inches labeled with and ' and “. You may not change main(), we will check to ensure it is exactly the same. The meters and inches can be doubles, but the feet...

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • IN JAVA 1. Create a program that prompts the user for an integer and then displays...

    IN JAVA 1. Create a program that prompts the user for an integer and then displays a message indicating whether or not the number is a perfect square. This can be determined by finding the square root of a number, truncating it (by casting the double result), and then squaring that result 2. Write a program that prompts the user for two numbers. The first number is a minimum value and the second number is a maximum value. RandomNum then...

  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • (Must be in C#) (Console will be my choice) Create a program called NarwhalCalc that will...

    (Must be in C#) (Console will be my choice) Create a program called NarwhalCalc that will be used to compute a narwhal's weight in tons based on its length in feet. Your program must use a method to do this and you must write this method. Your method must be called FeetToTons and the method must accept a parameter called feet (type double). The method should then use the formula shown below to calculate the narwhal's weight, then RETURN (not...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

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