Page 270 - Computer_Science_F5
P. 270

true. Otherwise, the program will stop
              executing. This means within IF…THEN
              statement, other options are ignored.
                                                                  YES         Condition
              The  following  is the  syntax  of IF….                                              Chapter Four: Object oriented programming with C++
          FOR ONLINE READING ONLY
              THEN statement.
                                                          Statement(s)
                  If(condition)                                                 NO
                  {

                  statements;

                  }
              Figure 4.38 shows  the execution
              flowchart of IF….THEN statement.               Figure 4.38: IF…THEN flowchart

              The following code in Program Example 4.20 shows how you can write a program
              to find average pass mark of the students to join form five PMC by using ‘If…Then’,
              the output is shown in Figure 4.39.

                        Program Example 4.20:

                     Using ‘If …Then’


                            #include<iostream>
                            using namespace std;
                            int main()
                            {
                                  int averageMark;
                                  cout<<”Enter marks of the student: “;
                                  cin>>averageMark;
                                  if(averageMark>=70)
                            {
                            cout<<”You have been selected to join form 5 PMC”<<endl;
                            }
                                 return 0;
                              }

                     Output:









                                     Figure 4.39: Output of program for marks


                                                    261
               Student’s Book  Form Five



     Computer Science Form 5.indd   261                                                     23/07/2024   12:34
   265   266   267   268   269   270   271   272   273   274   275