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

An if statement is used to test an expression for truth and execute some code based on it. Here’s a simple form of the if statement:

if (condition) {

  some code

}

If the condition is true, then the statements within are executed. Otherwise, the statements are skipped and the program continues on.

if (flip == 1) { std::cout << "Heads\n"; }

The if keyword is followed by a set of parentheses (). Inside the parentheses (), a condition is provided that evaluates to true or false:

  • If the condition evaluates to true, the code inside the curly braces {} executes.
  • If the condition evaluates to false, the code won’t execute.

So in the code above, if flip is equal to 1, the program outputs “Heads”; if it does not, then nothing happens and the program continues.

Instructions

1.

Inside grade.cpp, write an if statement where if grade > 60 is true, output “Pass”.

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?