I need a C program that will display a measurement in either
I need a C++ program that will display a measurement in either inches or centimeters. it should allow a user to convert between each. also the program should use two program-defined functions. Thanks!
Solution
main.cpp
#include <iostream>
using namespace std;
// function declaration
double inch2cm(double num1);
double cm2inch(double num2);
int main () {
// local variable declaration:
int menuOption;
double inches, centimeters,ret1,ret2;
cout << \"Enter the number (1) to convert centimeters to inches.\ \";
cout << \"Enter the number (2) to convert inches to centimeters.\ \";
cout << \"Menu Option: \";
cin >> menuOption;
cout << \"\ \ \";
switch (menuOption)
{
case 1:
cout << \"Please enter centimeters to convert to inches: \";
cin >> centimeters;
ret1 = cm2inch(centimeters);
cout << \"The conversion from centimeters to inches is : \"<<ret1 <<\"inches.\";
break;
case 2:
cout << \"Please enter inches to convert to centimeters: \";
cin >> inches;
ret2 = inch2cm(inches);
cout <<\"The conversion from inches to centimeters is : \"<<ret2<<\"centimeters.\";
break;
default:
cout << \"Unknown menu selection!\ \";
}
return 0;
}
double cm2inch(double num2)
{
double n2;
n2=num2*0.393701;
return n2;
}
double inch2cm(double num1) {
double n1;
n1=num1*2.54;
return n1;
}
Output :
