0% found this document useful (0 votes)
10 views3 pages

3-The Basics Part 2

Uploaded by

MOSTAFA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

3-The Basics Part 2

Uploaded by

MOSTAFA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Day 3

Mathematical expression:

Multiplication * , adding + , subtracting - , dividing / and modulus % are the main operator
discussed , please note that when dividing int by int it will result by int and when dividing int by
double it will result by double, but you need to define you result as double

Int x = 3 ;

double y = 2.0 ;

double result = x + y // result will be equal 5.0

Order of operations :

Any thing between parentheses is evaluated first like (2 + 2 ) * 9 the twos will be evaluated first the
order is as follow parentheses , power , multiplication and divide , adding and subtracting .

Writing Output to the Console :

there is a few operate to simplify the printing to the console instead of using std every time you can
put

using namespace std ;

after the #include <iostream >

so the standard output stream will be like that

cout << “hello world “ ;

also you can nest the printing like

cout << “hello world “ << “mister wonderful”;

to make an end line you use std::endl

cout << “hello world” << endl ; // start a new line if you print a new one
also you can nest more than two

cout << “hello world ” << << “mister wonderful” << endl

<< “how was your day? “;

<< called standard insertion operator

Reading from the Console:

Like the standard insertion operator there is also standard extraction operator to extract text from
the console using >>

Using

Cin >> variable name you can extract text from the console and do operation on it .

Cout << “what is your name?” << endl ;

String name; ;

Cin>> name ;

Cout << “my name is “ << name ;

You can also nest more than one output

Cout << define two numbers << endl ;

Int first, second ;

Cin >> first, second

Cout << “first number is : “ << first << endl

<< “second number is :” << second ;

You might also like