if2 - Programming If Statements Relational Operators Part 2...

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

View Full Document Right Arrow Icon
If Statements & Relational Operators, Part 2 Programming
Background image of page 1

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

View Full Document Right Arrow Icon
The if-else Statement Syntax if ( condition ) Action_A else Action_B if the condition is true then execute Action_A else execute Action_B Example: if (value == 0) cout << "value is 0"; else cout << "value is not 0"; condition Action_A Action_B true false
Background image of page 2
Choice ( if and else ) if <it's sunny>{ <go to beach> } else{ <take umbrella> }
Background image of page 3

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

View Full Document Right Arrow Icon
Finding the Big One int value1; int value2; int larger; cout << "Enter two integers: "; cin >> value1 >> value2; if (value1 > value2) larger = value1; else larger = value2; cout << "Larger of inputs is: " << larger << endl ;
Background image of page 4
Finding the Big One const double PI = 3.1415926; int radius; double area; cout << "Enter the radius of the circle: "; cin >> radius; if (radius > 0){ area = radius * radius * PI; cout << "The area of the circle is: " << area; } else cout << "The radius has to be positive " << endl ;
Background image of page 5

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

View Full Document Right Arrow Icon
Even or Odd int value1; bool even; cout << "Enter a integer : "; cin >> value; if (value%2 == 0) even = true; else even = false; // even = f &value%2);
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 18

if2 - Programming If Statements Relational Operators Part 2...

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

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