Week 2 Zsufyan
Week 2 Zsufyan
Computer Programming I
• Your program can then process those variables and produce output.
•The format of the cin is
cin >> value [>> values];
•The iostream.h header file contains the information C++ needs to use cin,
so include it when using cin.
•In C++, input is almost as simple as output. The input operator >> (also
called the get operator or the extraction operator) works like the output
operator <<
Example: in this example, the integer 32 is assigned to the variable x, and the value
of the expression x+23 is assigned to the variable y.
#include <iostream>
…………………….
int main()
{ //prints “x=32 and y=55”:
int x,y;
x = 32;
cout<<”x =”<<x;
y =x+23
cout<<”y =”<<y<<endl;
…………..
}
variable name
data type
char letter;
– Is used to reference a location in memory where a
value can be stored
– Must be defined before it can be used
– The value that is stored can be changed, i.e., it can
“vary”
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-
Wesley 2-22
Variables
total_Sales Yes
67
1 0
Initializing a variable
– Gives an initial value to a variable at the time
it is created
– Can initialize some or all of the variables
being defined
int length = 12;
int width = 7, height = 5, area;
- subtraction ans = 7 - 3; 4
* multiplication ans = 7 * 3; 21
/ division ans = 7 / 3; 2
% modulus ans = 7 % 3; 1