Previous Section  < Day Day Up >  Next Section

LAB 31: THE switch STATEMENT

  1. Rewrite the following script using a switch statement:

    
    #!/bin/csh –f
    
    # Grades program
    
    echo –n "What was your grade on the test? "
    
    set score = $<
    
    if ( $grade >= 90 && $grade <= 100 ) then
    
         echo You got an A\!
    
    else if ( $grade >= 80 && $grade <= 89 ) then
    
         echo You got a B.
    
    else if ( $grade >= 70 && $grade <= 79 ) then
    
         echo "You're average."
    
    else if ( $grade >= 60 && $grade <= 69 ) then
    
         echo Better study harder
    
    else
    
         echo Better luck next time.
    
    endif
    
    

  2. Rewrite the lookup script using switch statements for each of the menu items.

    Previous Section  < Day Day Up >  Next Section