Lesson 3

Input and Decisions

Students collect terminal input, compare values, and use if else logic to build a robot readiness checker.

Whiteboard-style C++ edit compile run cycle artwork

Video

Lesson video

Follow information into a program, test a true-or-false condition, and choose between the if and else paths.

Students practice

  • Read terminal input with cin.
  • Compare numbers with conditions such as batteryPercent >= 50.
  • Use if and else to choose between two messages.
  • Test both a passing input and a failing input.
  • Build a robot readiness checker.

Starter code

#include <iostream>

using namespace std;

int main() {
    int batteryPercent = 0;

    cout << "Enter battery percent: ";
    cin >> batteryPercent;

    if (batteryPercent >= 50) {
        cout << "Battery check passed." << endl;
    } else {
        cout << "Charge the battery before driving." << endl;
    }

    return 0;
}

What to turn in

  • A readiness checker that reads input.
  • A condition using if and else.
  • One passing and one failing test case.
  • A short explanation of the decision.