C++ Programming

This series of articles is developed from Storm Dragon's class.

Lesson 2:Doing Arithmetic in C++


Before you begin this lesson, please read these articles:

Declaring Variables

In order to use variables in a program, they must be declared.

The first order of business is to decide the scope of the variable: global or local. If the variable is needed for many different functions, it is declared prior to the code for these functions. Variables must be declared outside of the function in which they are used.

To declare a variable, we must know what kind of a variable it is. Here are some types of variables and what that type means:

integers or whole numbers
a decimal number
positive or negative number
positive number only
one character or byte
one or more characters or bytes



  1. Write, compile and test five related programs to prompt the user for two numbers. Prompt the user twice. Perform addition, subtraction, multiplication, division and modulo with these user provided numbers. Display the result to the user. Be sure your final prompt is on a separate line.
  2. Write, compile and test a program prompting the user to enter a name. Display the message:
    followed by the name entered. Be sure to have the final prompt appear on a separate line.
  3. Read the following articles: