Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 143 - CoreGPT(Podar)_Flipbook_C8
P. 143

    int t, h, m;

                         t = 500;
                         clrscr();
                         cout<< "Time in minutes is: " << t << "\n";

                         h = t / 60;
                                                                                     Time in minutes is: 500
                         m = t % 60;
                                                                                     Hours are: 8
                         cout<< "Hours are: " << h << "\n";
                                                                                     Minutes are: 20_
                         cout<< "Minutes are: " << m;
                         getch();
                     }
                     Relational Operators

                     Relational operators are used to compare the value of the two operands and return True or
                     False accordingly. They are binary operators as they need two operands to work. C++ provides

                     the following relation operators:
                      Operator        Name                       Description                     Example        Output
                                                                                              (x=8 and y=6)
                         ==       Equal to        It checks if the values of two operands          x == y        FALSE
                                                  are equal and returns True if both are
                                                  equal otherwise false.
                          !=      Not equal to    It checks if the values of two operands          x != y        TRUE
                                                  are not equal and returns false if both
                                                  are equal.
                          >       Greater than    It checks if the value of left operand is        x > y         TRUE
                                                  greater than the value of right operand.
                          <       Less than       It checks if the value of left operand is        x < y         FALSE
                                                  less than the value of right operand.

                         >=       Greater  than  It checks if the value of left operand is         x >= y        TRUE
                                  or equal to     greater  than  or  equal  to  the  value  of
                                                  right operand.

                         <=       Less  than  or  It checks if the value of left operand is        x <= y        FALSE
                                  equal to        less than or equal to the value of right
                                                  operand.

                     Clickipedia

                       In C++, the non-zero value is treated as true and zero value is treated as false.

                                                                                      Developing Programs in C++        141

| 138 139 140 141 142 143 144 145 146 147 148 |