Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-09-2009
Member
 
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?
Reply With Quote
  #2  
Old 02-09-2009
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #3  
Old 02-09-2009
Member
 
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!";
}
Reply With Quote
  #4  
Old 02-09-2009
Member
 
Join Date: May 2008
Posts: 2,383
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;
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to convert centimeter into feets and inches"
Thread Thread Starter Forum Replies Last Post
How to modify a Inch to Centimeter in Microsoft Excel Blake's MS Office Support 2 27-01-2012 08:01 PM
32 inches 1080p HDTV vs 30 inches 2560x1600 monitor Alibamu Monitor & Video Cards 5 28-09-2010 11:55 AM
Convert ruler, etc. from metric to inches in Office 2007 ... LAMONT D Office Setup 2 17-08-2009 06:23 PM
How to convert fractional inches into rounding numbers Rock Villa Software Development 2 01-07-2009 12:54 PM
TopCon GRS-1 finds you within 1 centimeter Orlando Portable Devices 3 21-03-2009 07:56 PM


All times are GMT +5.5. The time now is 03:15 AM.