Variable Types
Beginning C++
So far the only input that we could put into our programs has been intergers. Different variable types give you more input options and allow you to use things like letters for input. In this section, we will also talk about the ammount of memory the variables in your program are using.

                                                                                
Intergers
Intergers are numbers from 0 to 9 that can be negative or positive but cannot contain decimal places. Before you make a variable in a program you must declare it (int, followed by the variable name). Each data type takes up take up memory sapce. Intergers occupy 2 bytes of memory (16 bits) which means intergers can take values from -32,768 to 32,767. If you enter a number larger or lower than the limits, the program will store it as something else. If you want the variable to be a value that exceeds the 2 bytes, you can use qualifers to double the storage space for a variable. The four qualifiers in C++ are:

short int - Same as signed.
long int
- Occupy 4 bytes (32 bits) positive and negative values.
signed int
- The same as int (variable name);
unsigned int
- Can hold a value up to 65,535 but a negative value cannot be used.
(the bits and bytes listed above may differ depending on the compiler you are using) 

                                                                            
Floating Point
Floating types can have a decimal place, intergers, and exponents. Floating point will store 6 digits after the decimal point and will round up if any more are added. Examples of floating piont variables:

19
3.5576
0.4
4e7 (4 to the exponent of 7)

Exponents must be intergers (not decimals). Floating points are declared as follows: float (variable name);

                                                                                  
Double
The same as a floating point except it can hold values up to 10e308 (10 to the exponent of 308). It is declared like this: double (variable name);

                                                                                
Character
Characters can be anything on the keyboard (numbers and lettere). They will only store one character in memory so you cannot enter a two didgit number. This is how it is declared: char (variable name); For obtaining a certain response from your program using a character variable, you need to use a switch statement. An if or else or else if statement will not work in this case. To understand this, I think it is best to take a look at how it is written and do some trial programs yourself until you get it. There is a program illustrating a switch at the bottom of this page.

                                                                              
Boolean Type
This data type accepts true and false values only. Here is a little examp
le:
Input, Output and Variables
Operators
Looping
Variables
Functions
Boolean Type Program Illustrating a Switch
char letter;

cout << "enter a letter";
cin >> letter;

switch (letter) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout << "you chose a vowel\n";

break;

default:
cout << "you did not choose a vowel\n";
}
bool test;

cout << "one is greater than two\n";

cin >> test;

if (test == false) {
cout << "correct\n";
}
if (test == true) {
cout << "wrong\n";
}
In the program above illustrating a switch, letter is the variable and every vowel is a case. The output that follows will be displayed if a vowel is chosen. Default is just like else while using a switch. Break will stop execution of the second part of the switch so that it does not follow if a vowel is chosen.