10.Selection(C)(c++) - Selection Statements in C If...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection: Syntax: if (logical expression) statements1; else statements2; 1- One way selection: Syntax: if (logical expression) statements;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example 1: C++ Program // File: double.cpp /*The program corresponds to Example 1 on slide 5. It takes an integer and prints its double value if it is less than 50 */ #include <iostream.h> void main ( ) { int n ; cin >> n ; if (n < 50) cout << “The double value is “ << n * 2 << endl ; cout << “ Finished “ << endl; }
Background image of page 2
Example 2: C++ Program // File: Smaller.cpp /*The program corresponds to Example 3 on slide 14. It takes two integers and prints the smaller value using one output statement*/ #include <iostream.h> void main ( ) { int num1, num2 ; cin >> num1 >> num2 ; if ( num1 < num2 ) cout << “The smaller value is “ << num1 << endl ; else cout << “The smaller value is “ << num12 << endl ; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2011 for the course CHEMICAL E 2 taught by Professor Hibasaadeh during the Spring '11 term at University of Jordan.

Page1 / 7

10.Selection(C)(c++) - Selection Statements in C If...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online