Search This Blog

Pages

Wednesday, April 28, 2010 at 7:02 AM |

Decisions


Decisions are taken by us in
our daily life, so a program without decision is an empty box.


 


Keyword If
()and else


To add decisions in any C
program we can use the key word “If()”and “else ()”and you can also use if in an if and else in else but with
the C style


We
can also use”&&” for saying compiler “and” and for saying compiler or
we can use “or”


Structure
of if and else statement


The structure of if
statement is as follow:


 


if (your condition here) if you want to use “&&”
type  ((condition1 here) && (and
2 here)) and if you want to use “or” replace && with “or”


{


Statement
1 here ;


 


}


 


else


{


Statement
2 here ;


 


}


Our first decisions program


              #include <iostream.h>


 


              main ()


              {


                   int ho;


                   cout <<"how many
years old are you?" <<"\n" ;


                   cin >> ho;


                  


                   if (ho >= 18)


                   {


                          


                          cout <<
"you can play foot ball easily";


                          }


                      else


                      {


                          cout <<
"you can't play football";


                           


                            }


 


              }


Note:


You
can also use these programs by using operators. If you have any doubt you can
add pretences. Eg after declaring variables you can just type x=4 + y then the
x value will be 4+y’s value (but in the C’s typing style)

Posted by M.Hamza Ali Labels:

0 comments: