Back to Curriculum

10. Hypotenuse Calculator Practice Program

Project: Hypotenuse Calculator

Welcome to your first project! We're going to build a program that calculates the hypotenuse of a right triangle using the Pythagorean theorem.

The Pythagorean theorem states: a² + b² = c², where c is the hypotenuse.

To find the hypotenuse: c = √(a² + b²)

We'll need to:

  1. Get the lengths of the two sides from the user
  2. Calculate the squares of both sides
  3. Add them together
  4. Take the square root of the sum

Step 1: Set Up the Program

First, let's include the necessary libraries and set up our main function. We'll need <iostream> for input/output and <cmath> for the square root function.

🎉

Project Complete!

Congratulations! You've successfully built your first C++ program that combines multiple concepts: variables, user input, arithmetic operations, math functions, and output.

Back to Curriculum
main.cpp
Output
Click "Check Answer" to run your code.