Pages

Sunday, August 18, 2013

Write a program that that Converts Inches into other measurements in C++

Write a program that converts and prints a user-supplied measurement
 in unches into
1.  Foot  (12 inches)
2.  Centimeter (2.54/inch)
3.  Yard  (36 inches)
4.  Meter (39.37 inches)
5.  Kilometer (100) 

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
   #include <iostream.h>
   #include <conio.h>
   using namespace std;
   int main()
    {
    float inch,in , ft, cm, yrd, m, km;  
    cout << " Enter inche value:  ";
    cin  >> in; 
    ft   = in / 12;
    cm   = in / 0.39370;
    yrd  = in / 36;
    m    = in / 39.37;
    km   = in / 39370;
    cout << " Inches               = " << in  << " Inches \n" ;
    cout << " Inches to Foot       = " << ft  << "  Foot "  << endl;
    cout << " Inches to Centimeter = " << cm  << "  cm "    << endl;  
    cout << " Inches to Yard       = " << yrd << "  Yards " << endl; 
    cout << " Inches to Meter      = " << m   << "  Meter " << endl;
    cout << " Inches to KiloMeter  = " << km  << "  km " << endl;
    getch();
    return 0; 
             }    // main

Result:

 Enter inche value: 4
 Inches               = 4 Inches
 Inches to Foot       = 0.333333  Foot
 Inches to Centimeter = 10.16  cm  
 Inches to Yard       = 0.1111  Yards 
 Inches to Meter      = 0.1016 Meter 
 Inches to KiloMeter  = 0.0001015  km 

No comments:

Post a Comment