Page 53 - Modular_V2.0_C++_Flikpbook
P. 53

void main()
                   {

                     int n;
                     cout<< "Enter any number: ";
                     cin>> n;
                   if(n == 0)
                     break; //Error! Cannot use break with if
                   }
                    The above program when compiled will produce an error: Misplaced break.

                    MORE SOLVED PROGRAMS

                 Program 7: To find the largest in two numbers.
                 #include<iostream.h>

                 #include<conio.h>
                 void main()
                 {

                     clrscr();
                     int a, b;
                     cout<< "Enter two numbers: ";
                     cin>> a >> b;
                     if(a > b)
                     {

                         cout<< a << " is greater than " << b;
                     }                                                          DOSBox 0.74, Cpu speed: max 100% cycles,
                     else                                                   Enter two numbers: 15 54
                     {                                                      54 is greater than 15

                         cout<< b << " is greater than " << a;
                     }
                     getch();
                 }
                 Program 8: To take a character as input and display the season name according to the input
                 character.

                 #include<iostream.h>
                 #include<conio.h>
                 void main()
                 {
                     char code;
                     clrscr();
                     cout<< "Enter a character ";
                     cin>> code;

                                                                                                                  51
                                                                                           Conditional Statements
   48   49   50   51   52   53   54   55   56   57   58