Results 1 to 4 of 4

Thread: How to convert centimeter into feets and inches

  1. #1
    Join Date
    Jun 2009
    Posts
    1,205

    How to convert centimeter into feets and inches

    I would like to write a C++ program where a user is asked to enter the height in centimeters and then it displays the height in centimeters, feet and inches. Now here the condition is that the program should allow centimeters and inches in decimals. Another big question: how to do so? How can create a C++ conversion program from centimeters to feet and inches?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How to convert centimeter into feets and inches

    Well I can help you and give you the basic idea of the code but sorry to tell you that I don't have enough time to explain you the full code. You will have to do the trick. The main step (statement) of your code would be

    Code:
    inches = inches - feet*12;
    First convert the cms to inches and then calculate the feet from the calculates inches.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to convert centimeter into feets and inches

    Below is the code to convert centimeters into feets and inches:

    Code:
    const float cmtoinch = 2.54; 
    
    void main()
    {
            float cm, inch;
            int feet;
            do {
                    cout<<"Enter a height in centimeters: ";
                    cin>>cm;
                    if (cm <= 0) break;
                    inch = cm / cmtoinch;;
                    feet = inch/12;
                    inch = inch - (feet*12);
                    cout<< cm << " = " << feet<< " feet, " << inch << " inches" << endl;
            }while(cm > 0);
            cout<<"Done!";
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to convert centimeter into feets and inches

    You can even add the "try...catch" block to handle any unconditional exceptions. It should be something as below:

    Code:
    try
    {
    if(inch < 0)
    throw inch;
    
    if(feet < 0)
    throw feet;
    }
    
    catch (Exception e)
    {
    cout << "Negative values not accepted." << error << endl;
    }

Similar Threads

  1. How to modify a Inch to Centimeter in Microsoft Excel
    By Blake's in forum MS Office Support
    Replies: 2
    Last Post: 27-01-2012, 08:01 PM
  2. 32 inches 1080p HDTV vs 30 inches 2560x1600 monitor
    By Alibamu in forum Monitor & Video Cards
    Replies: 5
    Last Post: 28-09-2010, 11:55 AM
  3. Replies: 2
    Last Post: 17-08-2009, 06:23 PM
  4. How to convert fractional inches into rounding numbers
    By Rock Villa in forum Software Development
    Replies: 2
    Last Post: 01-07-2009, 12:54 PM
  5. TopCon GRS-1 finds you within 1 centimeter
    By Orlando in forum Portable Devices
    Replies: 3
    Last Post: 21-03-2009, 07:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,262,225.15209 seconds with 16 queries