C++ Program to Convert Centimeters to Feet and Inches

In this post, we will learn how to convert centimeters to feet and inches using C++ Programming language.

There are 2.54 cm in 1 inch. To convert cm to inches, divide cm figure by 2.54.

There are 12 inches in a foot, so to convert inches to foot, divide inches by 12 to get the length in feet.

We will be using the above metrics in our program to perform the conversion.

So, without further ado, let’s begin this tutorial. 

C++ Program to Convert Centimeters to Feet and Inches

// C++ Program to Convert Centimeters to Feet and Inches
#include <iostream>
using namespace std;

int main(){
    float cm, feet, inches;
    
    // Asking for input
    cout << "Enter the length in centimeters: ";
    cin >> cm;
    
    // Conversion
    inches = cm / 2.54;
    feet = inches / 12;
    
    // Displaying output
    cout << cm << " cm is equals to: " << inches << " inches" << endl;
    cout << cm << " cm is equals to: " << feet << " feet";
    return 0;
}

Output

Enter the length in centimeters: 21
21 cm is equals to: 8.26772 inches
21 cm is equals to: 0.688976 feet

How Does This Program Work ?

    float cm, feet, inches;

In this program, we have declared three float data type variables named cm, feet and inches.

    // Asking for input
    cout << "Enter the length in centimeters: ";
    cin >> cm;

Then, the user is asked to enter the length in centimeters.

    // Conversion
    inches = cm / 2.54;
    feet = inches / 12;

We convert cm to inches by dividing the cm figure by 2.54. [1 inch = 2.54 cm]
We convert the length to feet by dividing the total inches obtained above by 12. [ 1 Foot = 12 inches]

    // Displaying output
    cout << cm << " cm is equals to: " << inches << " inches" << endl;
    cout << cm << " cm is equals to: " << feet << " feet";

Finally, the output is displayed on the screen using the cout statement.

Conclusion

I hope after going through this post, you understand how to convert centimeters to feet and inches using C++ Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to solve your query.

Also Read:

Leave a Comment

Your email address will not be published.