Question
C++ Create a centimeters to inches and inches to centimetersconverter. Ask the user to choose which option they want to go withor exit the menu.
C++
- Create a centimeters to inches and inches to centimetersconverter. Ask the user to choose which option they want to go withor exit the menu. For options 1 and 2, ask for inches and/orcentimeters to be converted, then calculate the conversion andprint out the results. The menu should look something like thefollowing:
- Menu of Options
1. Convert centimeters to inches
2. Convert Inches to centimeters
3. Exit
Enter a choice:
- Menu of Options
- Use a do while loop for the menu ofoptions.
- The formula for option 1: inches = centimeter/2.54
- The formula for option 2: centimeters = inches* 2.54
- In this lab, you are learning towrite separate functions that can be called on in yourprogram. The 2 functions you need to write are: centimeters toinches and inches to centimeters. Review example code belowfor instructions on how to do the lab:
//This example can be used as a starting point for the lab
#include
using namespace std;
//prototype for the functions are needed if you place thefunctions below main
void centimetersToinches();
void inchesTocentimeters();
int main()
{
int choice;
do{
cout << "Menu ofOptions"
<< "1. Convert centimeters to inches"
<<"2. Convert Inches to centimeters"
<<"3. Exit"
<<"Enter a choice:";
cin >>choice;
switch(choice)
{
case 1:
centimetersToinches(); //calling centimeters toinches convert
break;
case 2:
//Here you can callthe inches to centimeters function
break;
case 3:
//Here you will adda proper exit message
break;
default:
//Here you will adda proper error message if user inputs anything that's//not 1,2, or 3};
}
}while(choice !=3);
return 0;
}
void centimetersToinches()
{
//define variables
double inches, centimeters;
//ask the user for centimeters
cout <<"Enter number ofcentimeters to convert to inches: ";
cin >> centimeters;
//convert centimeters to inches
inches = centimeters /2.54;
//print the results
cout << "There are " <
}
void inchesTocentimeters()
{
//define variables
//ask the user for inches
//convert inches to centimeters
//print the results
}
Step by Step Solution
3.48 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
C program to convert inches to centimeters and viceversa include using namespace std prototype for t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started