Log in from a computer to take this course

You'll need to log in from a computer to start Learn C++. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Before we dive deep into the syntax of the if statement, let’s do a demo!

Coin Toss

Here, we have coinflip.cpp program that simulates a coin toss:

  • 50% of the time, it’s Heads.
  • 50% of the time, it’s Tails.

Instructions

1.

Run the program 5 times to see an if else statement in action!

How many times did it go Heads?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?