Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

could anyone help? I\'m lost:( his exercise, you will create a program that disp

ID: 3804436 • Letter: C

Question


could anyone help? I'm lost:(

his exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create new project Project, and save it in the Cpp8WChap09 folder. The program should allow the user the choice of converting a measurement from inches to centimeters or vice versa. Use two program-defined functions: one for each different conversion type. Enter your C++ instructions into a source file named Introductory18.cpp. Also enter appropriate comments and any additional instructions required by the compiler Test the applica- tion appropriately.

Explanation / Answer

C++ code:

#include <bits/stdc++.h>
using namespace std;

float cmtoinch(float n)
{
   return n*(0.393701);
}
float inchtocm(float n)
{
   return (n/0.393701);
}

int main()
{
   cout << "Enter 1 to convert From CM to Inch" << endl;
   cout << "Enter 2 to convert From Inch to CM" << endl;
   int c;
   cin >> c;

   if(c = 1)
   {
       cout << "Enter length in cm!" << endl;
       float len;
       cin >> len;
       cout << len << " CM = " << cmtoinch(len) << " Inch!" << endl;
   }
   else if(c = 2)
   {
       cout << "Enter length in Inch!" << endl;
       float len;
       cin >> len;
       cout << len << " Inch = " << inchtocm(len) << " CM!" << endl;
   }
   else
   {
       cout << "Invalid input!" << endl;
   }

   return 0;
}

Sample Output:

Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
1
Enter length in cm!
1
1 CM = 0.393701 Inch!

C:UsersAkashDesktopcheggc++ io>a
Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
2
Enter length in cm!
0.393702
0.393702 CM = 0.155001 Inch!

C:UsersAkashDesktopcheggc++ io>a
Enter 1 to convert From CM to Inch
Enter 2 to convert From Inch to CM
3
Enter length in cm!
3
3 CM = 1.1811 Inch!