Search⌘ K

Making Decisions with AI

Learn C++ if/else statements and comparison operators by building a smart thermostat that decides whether to heat or cool your home.

The project

You’ve just moved into a great neighborhood, but your new home needs an upgrade to its automated temperature control system.

Currently, the thermostat is fairly basic; it can’t determine whether to turn on the air conditioning or the heater. A static display that says Temperature is 25 isn’t very useful. What you really need is a system that can make decisions based on the temperature and your individual comfort level.

With your confidence in your C++ skills now, you aim to create this thermostat logic yourself! This smart home system should compare the current room temperature with the user’s preferred comfort temperature and then determine the appropriate action.

The programming concept

Imagine this:

You’re writing a program, and you want it to say:

  • You can vote! If the person is 18 or older.

  • Sorry, too young. If they’re younger than 18.

How would you say that in plain English?

If age is 18 or more → say yes. Otherwise → say no.

C++ can do that. Let’s try it together:

C++
int age;
cout << "How old are you? ";
cin >> age;
if (age >= 18) {
cout << "You can vote!" << endl;
}
else {
cout << "Sorry, too young." << endl;
}

How do you read this code? In lines 1–3, it asks the user for their age and stores ...