
© Alex Allain (www.cprogramming.com)
Using Nano .......................................................................................................................................... 40
Chapter 2: The Basics of C++ ................................................................................................................. 43
Intro to the C++ language ....................................................................................................................... 43
The simplest C++ program .................................................................................................................. 43
What happens if you don't see your program? .................................................................................. 45
The basic structure of a C++ program ................................................................................................. 45
Commenting your programs ................................................................................................................... 46
Thinking like a programmer and creating reusable code ....................................................................... 47
A few words on the joys and pain of practice ......................................................................................... 47
Quiz yourself ........................................................................................................................................... 48
Practice problems ................................................................................................................................... 49
Chapter 3: User Interaction and Saving Information with Variables .................................................... 50
Declaring variables in C++ ................................................................................................................... 50
Using variables .................................................................................................................................... 50
What if your program exits immediately? .......................................................................................... 51
Changing, using and comparing variables........................................................................................... 52
Shorthand for adding and subtracting one ......................................................................................... 52
The use and misuse of variables ............................................................................................................. 54
Common errors when declaring variables in C++ ............................................................................... 54
Case sensitivity .................................................................................................................................... 55
Naming variables ................................................................................................................................. 55
Storing strings ......................................................................................................................................... 56
Okay, I get strings—but why all those other types? ............................................................................... 58
Quiz yourself ........................................................................................................................................... 60
Practice problems ................................................................................................................................... 61
Chapter 4: If Statements ....................................................................................................................... 62
Basic syntax for if .................................................................................................................................... 62
Expressions.............................................................................................................................................. 63
What is truth? ..................................................................................................................................... 63
The bool type ...................................................................................................................................... 64
Else statements ....................................................................................................................................... 65
Else-if ....................................................................................................................................................... 65
String comparisons .................................................................................................................................. 66
More interesting conditions using Boolean operators ........................................................................... 66
Boolean not ......................................................................................................................................... 67