Lesson 2

Program Structure and Variables

Students use comments, indentation, naming rules, and variables to build a readable robot profile program.

Whiteboard-style robotics C++ artwork

Video

Lesson video

See how program structure and named variables make robot information easier to read, change, and explain.

Students practice

  • Read the structure of a simple C++ program.
  • Use comments and indentation to make code easier to follow.
  • Create string, int, and double variables.
  • Use meaningful variable names.
  • Print labeled robot-profile output with cout.

Starter code

#include <iostream>
#include <string>

using namespace std;

int main() {
    string robotName = "PracticeBot";
    int teamNumber = 12345;
    double batteryVoltage = 12.6;
    int motorCount = 4;

    cout << "Robot name: " << robotName << endl;
    cout << "Team number: " << teamNumber << endl;
    cout << "Battery voltage: " << batteryVoltage << " volts" << endl;
    cout << "Motor count: " << motorCount << endl;

    return 0;
}

What to turn in

  • A robot profile using string, int, and double.
  • Clear labels and meaningful variable names.
  • At least one useful comment.
  • Terminal output from the completed program.