/* This program demonstrates * 1. The simple if statement * 2. Nested if statements * 3. Indentation for readability * * 1. The simple if...else statement. * The if ...else statement is a way to get C++ to execute different lines * of code depending on the truth value of a condition. If the condition * were true, C++ executes the statements in the if block and skips over * the else block. If the condition were false, C++ skips over the if * block and executes the statements in the else block. * Once the if..else statement is done, C++ continues with the first line * after the if...else statement. * Both "if" and "else" are keywords. * 1. Only the if part requires a condition. NO CONDITION FOR ELSE * 2. The else part is optional, while the if part is not. WE CANNOT WRITE * AN ELSE BLOCK WITHOUT THE IF BLOCK * * 2. The Nested if statement * Since the contents of the if block (Code that is executed if the condition is true) * can consist of multiple statements enclosed in {}, we can write an if statement * inside the if block (or the else block). This process is called Nesting. The * following example shows one level of Nesting, but there is no theoretical limit to * the number of nested levels. * Also, we can have multiple if statements with nesting and nested if statements, where * the internal level is a multiple if. Any combination of control structures is allowed * as long they are syntactically OK. * * 3. Style Guidelines - Indentation * It is standard practice to indent code to make it readable. * Whenever we begin a block of code by opening '{', we go one tab in, and whenever we end a * block of code with a '}', we go one tab out. * This gives us 3 advantages - we can easily match which '{' corresponds to which '}' * We can make sure there are no missing or stray '{' or '}', which would cause compiler errors. * We can easily understand which lines of code belong in a cod block. */ #include using namespace std; int main() { /* Here, we calculate if a student will pass the class. * you can pass this class only if you have a C- on the entire class AND * a C- average on the milestones. * Here we read in the grades. Practice exercise, discussion sessions and class * participation on 8% each, exams on 39% and hw assignments on 35% */ double cp,pe,ds,exam, hw; //already weighted grades for class participation, practice // exercises, discussion sessions, exams and hw assignments cout<<"Enter the grades: "; cin>>cp>>pe>>ds>>exam>>hw; double mileAvg = exam / 39 * 100 ; // test avgerage on 100 double grade = cp + ds + pe + exam +hw + 2; // 2 points for 1st day quiz, help sessions //Now, we are ready to write the if statement //To pass, students need 70% overall and 70% average on milestone assignments. if (grade>=70 && mileAvg >=70) { cout<<"You passed! Congratulations!"<y? If yes, 2.1.1. If no, 2.2 * 2.1.1 x>z? If yes, largest = x. Otherwise largest = z. Go to step 3 * 2.2 y>z? If yes, largest =y. Otherwise largest = z. * 3. Print the largest - cout */ int x,y,z; cout<<"Enter 3 distinct numbers: "; cin>>x>>y>>z; int largest; if (x > y) { if(x > z) { largest = x; } else { largest = z; } } else { if (y > z) { largest = y; } else{ largest = z; } } // Note the indentation for the above structure. cout<