## Key Concepts

Review core concepts you need to learn to master this subject

### Variables

// Declare a variable int score; // Initialize a variable score = 0;

A variable refers to a storage location in the computer’s memory that one can set aside to save, retrieve, and manipulate data.

### int Type

// Declare a variable int score; // Initialize a variable score = 0;

int is a type for storing integer (whole) numbers. An integer typically requires 4 bytes of memory space and ranges from -2³¹ to 2³¹.

### double Type

// Declare a variable int score; // Initialize a variable score = 0;

double is a type for storing floating point (decimal) numbers. Double variables typically require 8 bytes of memory space.

### Arithmetic Operators

// Declare a variable int score; // Initialize a variable score = 0;

C++ supports different types of arithmetic operators that can perform common mathematical operations:

• + addition
• - subtraction
• * multiplication
• / division
• % modulo (yields the remainder)

### User Input

// Declare a variable int score; // Initialize a variable score = 0;

std::cin, which stands for “character input”, reads user input from the keyboard.

Here, the user can enter a number, press enter, and that number will get stored in tip.

### Chaining the Output

// Declare a variable int score; // Initialize a variable score = 0;

std::cout can output multiple values by chaining them using the output operator <<.

Here, the output would be I'm 28.

### char Type

// Declare a variable int score; // Initialize a variable score = 0;

char is a type for storing individual characters. Characters are wrapped in single quotes '. Characters typically require 1 byte of memory space and range from -128 to 127.

### string Type

// Declare a variable int score; // Initialize a variable score = 0;

std::string is a type for storing text strings. Strings are wrapped in double quotes ".

### bool Type

// Declare a variable int score; // Initialize a variable score = 0;

bool is a type for storing true or false boolean values. Booleans typically require 1 byte of memory space.

Variables
Lesson 1 of 1
1. 1
The “Hello World!” program simply writes to the screen. It does not read anything, calculate anything, or allow for user input. That’s no fun! Real programs tend to produce results based on some …
2. 2
“Every variable in C++ must be declared before it can be used!” Suppose we are building a game and we want to keep track of a player’s score that goes from 0 to 10. We need a variable! Before w…
3. 3
After we declare a variable, we can give it a value! Suppose that we have declared an int variable called score, to set it to 0, we can simply write: score = 0; - The score is the name of the v…
4. 4
We can both declare and assign a value to a variable in a single initialization statement. Suppose we have these two lines: // Declare a variable int score; // Initialize a variable score = 0; …
5. 5
Computers are incredible at doing calculations. Now that we have declared variables, let’s use them with arithmetic operators to calculate things! Here are some arithmetic operators: - + additi…
6. 6
Now that we have outputted a variable and have also outputted things using multiple couts. Let’s take a closer look at cout again. If we have the code below: int age = 28; std::cout << “Hello, …
7. 7
Like we mentioned in the introduction, another way to assign a value to a variable is through user input. A lot of times, we want the user of the program to enter information for the program. We h…
8. 8
Now that we’ve learned about the basics of variables and cin, let’s write a program! The mad scientist Kelvin has mastered predicting the weather in his mountain-side meteorology lab. Recently, K…
9. 9
Let’s go back to the temperature.cpp that we wrote. This time, instead of giving tempf a value of the current temperature in New York: tempf = 83; Let’s ask the user what the temperature is …
10. 10
You made it to the end of the lesson! High five. 🙌 Here is a review of the lesson: - A variable represents a particular piece of your computer’s memory that has been set aside for you to use to s…

## What you'll create

Portfolio projects that showcase your new skills ## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory 