Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 42

Thread: Day 4 - Decision Making - Become PHP Expert in 30 days

  1. #31
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    http://php.flashwebhost.com/vineesh/...n_making_1.php

    Code:
    <?php
    
    $ticket = 'no';
    
    if ($ticket == 'yes') {
    
    echo 'We will get ticket' ;
    
    }
    
    if ($ticket == 'no') {
    
    echo 'We will not get ticket' ;
    
    }
    ------------------------
    http://php.flashwebhost.com/vineesh/...n_making_2.php
    Code:
    <?php
    
    $mark = 99;
    
    if ($mark == 99) {
    
    echo 'You have got 99 marks, you win!';
    
    }
    
    if ($mark == 19) {
    
    echo 'Sorry, You are failed';
    
    }

  2. #32
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    http://php.flashwebhost.com/vineesh/...n_making_3.php

    and my code is as follows:
    Code:
    <?php
    
    $passMark = 35;
    
    $student1Name = 'Manu';
    $student1Mark = 34;
    
    $student2Name = 'Saritha';
    $student2Mark = 60;
    
    $student3Name = 'Sudhi';
    $student3Mark = 93;
    
    $class1 = 'First Class';
    $class2 = 'Distinction';
    
    echo 'Passmark = ' . $passMark . '<br> <br>' ;
    
    echo 'Student names with marks <br> <br>';
    
    echo $student1Name . ' = ' . $student1Mark . ' marks. <br>' ;
    echo $student2Name . ' = ' . $student2Mark . ' marks. <br>' ;
    echo $student3Name . ' = ' . $student3Mark . ' marks. <br> <br>' ;
    
    if ($student1Mark < $passMark) {
    
    echo $student1Name . ', you have got only ' . $student1Mark . ' marks and you are failed. <br>' ;
    
    }
    
    if ($student2Mark > $passMark) {
    
    echo $student2Name . ', you have got ' . $student2Mark. ' marks and you passed with ' . $class1 . '<br>' ;
    
    }
    
    if ($student3Mark > $passMark) {
    
    echo 'Congratulations ! ' . $student3Name . '!. You have got ' . $student3Mark . ' marks and you passed with ' . $class2 ;
    
    }

  3. #33
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 4 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/trai..._Ernakulam.php

    Code:
    <?php
    
    
    $trainGoesToErnakulam = 'no';
    
    
    if ($trainGoesToErnakulam == 'yes')
    
    
    {
    
    
    echo 'I Will Enter The Train.';
    
    
    }
    
    
    if ($trainGoesToErnakulam == 'no')
    
    
    {
    
    
    echo 'I Will Not Enter The Train.';
    
    
    }

  4. #34
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 4 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/if_greater.php

    Code:
    <?php
    
    
    $passMark = '35';
    
    
    $studentName = 'Tom';
    
    
    $studentMark = '60';
    
    
    if ($studentMark>$passMark) 
    
    
    {
    
    
    echo 'Congratulations '. $studentName . ' ! You passed exam with ' . $studentMark . ' marks.';
    
    
    }

  5. #35
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 4 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/if_else_greater.php

    Code:
    <?php
    
    
    $passMark = '35';
    $studentName = 'Tom';
    $studentMark = '30';
    
    
    if ($studentMark > $passMark) {
    echo 'Congratulations '. $studentName . ' ! You passed exam with ' . $studentMark . ' marks.';
    
    
    } else {
    
    
    echo ' Sorry! You failed. Good luck next time.' ;
    
    
    }

  6. #36
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 4 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/if_else_greater_bug.php

    Code:
    <?php
    
    $passMark = '35';
    $studentName = 'Tom';
    $studentMark = '35';
    
    
    if ($studentMark >= $passMark) {
    
    
    echo 'Congratulations ' . $studentName . ' ! You passed exam with ' . $studentMark . ' marks' ;
    
    
    }
    
    
    else
    
    
    {
    
    
    echo 'Sorry! You failed. Good luck next time.' ;
    
    
    }
    Last edited by vineesh; 05-14-2014 at 11:31 AM.

  7. #37
    Join Date
    Oct 2003
    Location
    Kochi, Kerala, India
    Posts
    21,389

    Default

    http://php.flashwebhost.com/vineesh/...n_making_5.php

    Code:
    <?php
    
    $rain = 'eeeee';
    
    if ($rain == 'yes') {
    
    echo 'It will rain today.'; 
    
    }
    
    else if ($rain == 'no') {
    
    echo 'It will not rain today.'; 
    
    }
    
    else {
    
    echo 'huh...what is this ?';
    
    }

  8. #38
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 4 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/cow_version_2.php

    Code:
    <?php
    
    
    $trainGoesToErnakulam = 'when';
    
    
    if ($trainGoesToErnakulam == 'yes') {
    
    
    echo 'I Will Enter The Train.'; }
    
    
    else if ($trainGoesToErnakulam == 'no') 
    
    
    {
    
    
    echo 'I Will Not Enter The Train.';
    
    
    }
    
    
    else
    
    
    {
    
    
    echo 'I will go at 11 AM.';
    
    
    }

  9. #39
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    { and } not properly aligned in tom and vineesh's codes. It should be like

    Code:
    if (CONDITION) {
        // do some thing if true
    } else {
       // do another thing
    }
    It is OK, just coding style, it is better to follow proper coding style from the beginning.

    Variable names are perfect.

    Updated code for

    http://php.flashwebhost.com/vineesh/...n_making_5.php

    Code:
    <?php
    
    $rain = 'eeeee';
    
    if ($rain == 'yes') {
        echo 'It will rain today.'; 
    } else if ($rain == 'no') {
        echo 'It will not rain today.'; 
    } else {
        echo 'huh...what is this ?';
    }
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  10. #40
    Join Date
    Jan 2008
    Location
    india,kerala-god's own country
    Posts
    14,007

    Default

    PHP PROGRAMING DAY - 4 MY 1'ST CODE

    http://php.flashwebhost.com/ramesh/d..._is_better.php

    Code:
    <?php
    
    $sachinisbetter = 'yes';
    
    if ($sachinisbetter =='yes'){
        echo 'Sachin is a great cricketer. He is better than Lara';
    }
    
    echo '<br>';
    
    $laraisbetter = 'no';
    
    if ($laraisbetter == 'yes'){
    echo 'Lara is better than sachin';
    }
    Last edited by rameshxavier; 05-15-2014 at 10:27 AM.

Page 4 of 5 FirstFirst ... 2345 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •