In this exercise you will create a program that displays a m

In this exercise, you will create a program that displays a measurement in either inches

or centimeters. If necessary, create a new project named Introductory17 Project, and

save it in the Cpp8\\Chap10 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 Introductory17.cpp. Also, enter appropriate comments and any additional

instructions required by the compiler. Test the application appropriately.

In this exercise, you will create a program that displays a measurement in either inches

or centimeters. If necessary, create a new project named Introductory17 Project, and

save it in the Cpp8\\Chap10 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 Introductory17.cpp. Also, enter appropriate comments and any additional

instructions required by the compiler. Test the application appropriately.

Solution

#include <iostream>
#include <iomanip>
using namespace std;

void cmstoinches()
{
   double cms,inches;
   cout<<\"\ Enter centimetres\";
       cin>>cms;
      
       inches = cms/2.54; //cms to inches conversion
      
   cout<<\"\ \"<<cms<<\" centimetres = \";
   cout<< setprecision(2) << fixed<<inches<<\" inches\";
}

void inchestocms()
{
   double inches,cms;
   cout<<\"\ Enter inches\";
       cin>>inches;
      
       cms = inches*2.54;
      
       cout<<\"\ \"<<inches<<\" inches = \";
       cout<<setprecision(2) << fixed<<cms<<\" centimetres\";
      
}
  

int main()
{
   int choice;
   double cms,inches;
   cout<<\"\ Enter 1 to convert inches to centimetres and 2 to convert centimetres to inches\";
   cin>>choice;
  
   if(choice == 1) //inches to cms conversion
   {
   inchestocms();  
   }
   else if(choice == 2)
   {
   cmstoinches();      
      
   }
  
  
  
   return 0;
}

output:

In this exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create a new project named Introductory17
In this exercise, you will create a program that displays a measurement in either inches or centimeters. If necessary, create a new project named Introductory17

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site