C++ Programming

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

Lesson 2:Doing Arithmetic in C++

Reading

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:

int
integers or whole numbers
double
a decimal number
signed
positive or negative number
unsigned
positive number only
char
one character or byte
string
one or more characters or bytes

Notes:

Assignment

  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:
    Hello,
    
    followed by the name entered. Be sure to have the final prompt appear on a separate line.
  3. Read the following articles: