How do I do this In this exercise you will create a program


How do I do this?

In this exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create a new project named Introductory!? Project, and save it in the Cpp8\\ Chap 10 folder. The program should allow the user the choice of converting a measurement from inches to centimeters or vice versa. Use two void functions: one for each different conversion type. Enter your C++ instructions into a source file named Introductoryl7.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Test the application appropriately.

Solution

#include <iostream>

using namespace std;

//function to convert Inches To Centeimeters
void convertInchesToCMs(double inches,double *result)
{
*result=inches * 2.54;
}
//function to convert Centeimeters To Inches
void convertCMsToInches(double centmeters,double *result)
{
*result=centmeters / 2.54;
}
int main()
{
//declaration
int choice;
double result;
double inches;
double centmeters;

//prompt for choice
cout<<\" MENU\ 1. Convert inches to centimeters\ 2. Convert centimeters to inches\ \";
cout<<\"Enter your choice:\";
cin>>choice;

//case to choose
switch(choice)
{
case 1:
{
cout<<\"Enter inches:\";
cin>>inches;
convertInchesToCMs(inches,&result);
cout<<\"Result in CM:\"<<result<<endl;
}
break;
case 2:
{
cout<<\"Enter inches:\";
cin>>centmeters;
convertCMsToInches(centmeters,&result);
cout<<\"Result in Inches:\"<<result<<endl;
}
break;
default:
cout<<\"Invalid choice \"<<endl;
}

return 0;
}

OUTPUT:

MENU
1. Convert inches to centimeters
2. Convert centimeters to inches
Enter your choice:1
Enter inches:2
Result in CM:5.08

 How do I do this? In this exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create a new project n
 How do I do this? In this exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create a new project n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site