Selection+Control+Structures+(If+statements)

**-**Tell the compiler to examine the relationship between two values. **-**The equal to operator (==) and not equal to operator (!=) have lower precedence than the other relational operators.
 * Relational Operators **
 * **(<)** Less than || (a)** Greater than || (a>b) || **ex.)** score > 80 “score is greater than 80” ||
 * **(<=)** Less than or equal to || (a<=b) || **ex.)** score<=60 “score is less than or equal to 60” ||
 * **(>=)** Greater than or equal to || (a>=b) || **ex.)** score>=80 “score is greater than or equal to 80” ||
 * **(==)** Equal to || (a==b) || **ex.)** score == 20 “score is equal to 20” ||
 * **(!=)** Not equal to || (a!=b) || **ex.)** score!=10 “score is not equal to 10” ||
 * Precedence **

media type="custom" key="5689001" 
 * If statements with single alternatives.**

In order to make decisions, we sometimes have to evaluate one or more factors. Computer programs must also be able to select from alternative courses of action, depending on the situations they encounter. This is why control structures that handle these are called selection structures.

In C++ the primary selection structure is the **if statement. **This statement is used to evaluate a single condition, and perform a specific action if that condition turns out to be true. All if statements begin with the keyword **if,** followed by the Boolean expression and then the C++ statement to be performed if the condition evaluates to true.
 * Example 1. **

private: System::Void btnGrade_Click(System::Object^ sender, System::EventArgs^ e) { Int score; Int32::Tryparse(txtScore->Text,score); If (score>=60) txtGrade->Text= “Pass” ; }

To indicate you want to include multiple statements in an alternative, you must enclose the multiple statements in curly brackets { }. As in the previous example there is no set course of action if the score is less than 60. It only has tasks for situations that evaluate to true
 * Example 2. **

private: System::Void btnGrade_Click(System::Object^ sender, System::EventArgs^ e) { Int score; Int32::Tryparse(txtScore->Text,score); If (score>=60) { txtGrade->Text= “Pass” ; txtGrade->BackColor=Color::Green } }

As you can s​ee example 2 consists of two parts. In example 2 a score of 60 or greater results in the word “Pass” being displayed on a green background.

Nesting is a programming technique in which you place one control structure inside of another.
 * Nested Control Structures & If..else Statements **

Int  num1,num2 <span style="font-family: 'Arial','sans-serif'; font-size: 10pt;"> if ((txtLeft->Text==” “) || (txtRight->Text==” “)) MessageBox::Show (“Empty Operand”); Else { //Nested Structures If (cmbOperator->SelectedIndex== -1) MessageBox::Show(“Missing Operator”); Else { Int32::TryParse(txtLeft->Text, num1); Int32::TryParse(txtRight->Text, num2); } }

<span style="font-family: 'Arial','sans-serif'; font-size: 9.5pt;">The first decision point in the code evaluates the operands to make sure both have been entered

if ((txtLeft->Text==” “) || (txtRight->Text==” “))

If not, an error message is produced. Even if the operands are present, we can’t process the data until the program has checked to make sure an operator has been selected in the combo box.

If (cmbOperator->SelectedIndex== -1) MessageBox::Show(“Missing Operator”); Else

The conditional expression of the inner structure compares the values used in the combo box which are expressed in selected indexes and -1 means there is no selected operand.


 * //Combo Boxes and switch Statements//**

Combo Boxes || Combo boxes are used to allow the user to pick options from a drop down list of items || switch (cboFrom->SelectedIndex) { case (0):amount=amount*(1); break ; case (1):amount=amount*(10); break ; } || 177 || switch Statements || Switch statements allow you to specify an integral variable, or expression, amd then specify actions for each possible value. || switch (integral value or expression) { case integral value 1: statements;[ break ;] case integral value 2: statements;[ break ;] .  .  .  case integral value n: statements; [ break ;] [ default : statements;] } || 185 ||
 * Name ** ||
 * Purpose ** ||
 * Code Example ** ||
 * Pg# ** ||
 * Pg# ** ||