C++ Lesson 2
C++ Lesson 2
C++
By Eng.Adulahi M. Adan
http://www.mahergelle.com
Chapter One: -
C++ Variables &
User Input
C++ Variables
Contents
Display Variables
The cout object is used together with the << operator to
display variables.
To combine both text and a variable, separate them with
the << operator:
Example
int myAge = 35;
cout << "I am " << myAge << " years old.";
C++ Variables
Contents
int x, y, z;
x = y = z = 50;
cout << x + y + z;
C++ Identifiers
Contents
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Type a number: "; // Type a number and press enter
cin >> x; // Get user input from the keyboard
cout << "Your number is: " << x;
return 0;
}
C++ User Input
Contents