Académique Documents
Professionnel Documents
Culture Documents
The statements
Val1 = 10;
Val2 = Val1 + 5;
Assigns values to the two variables. The
equal sign =, causes the value on R.H.S to
be assigned to the variable on the L.H.S.
void main ( )
{
int var1, var2; // defines two variables
var1 = 20; // assign value
var2 = var1 + 10;
cout << “var1 + 10 is “; // output text
cout << var2; // output value
}
CHARACTER VARIABLES
void main ( )
{
char var1 = ‘A’, var2 = ‘B’, var3 = ‘ ’;
cout << var1 <<var3 << var2;
}
INPUT with cin
# include <iostream.h>
void main ( )
{
int ftemp;
cout << “Enter temperature in
fahrenheit : “;
cin >> ftemp;
int ctemp = (ftemp-32) * 5 / 9;
cout << “Equivalent in Celsius is : “ <<
ctemp ;
}
INPUT with cin
•The cin statement causes the program to wait for
the user to type in a number.
•The keyword cin is an object in C++ to correspond
to the standard input stream. This stream represents
data coming from the keyboard.
•The >> is the extraction or get from operator. It
takes the value from the stream object (i.e. cin
object) on L.H.S and places it in the variable on its
R.H.S.
Note: The extraction (<<) and insertion (>>)
operators can be used repeatedly in a statement.
Floating Point Variables