Please,
If you enter r or R it should ouput Red and if you enter w or W it should 
output White beause it is a conditional statement the case there means if a key 
is entered it should return it corresponding figure or Output, that is the main 
idea about that. You can try to enter any key it will not give you any Output.
So try

Prince Annan Koomson

--- On Thu, 6/18/09, ayyaz <[email protected]> wrote:

From: ayyaz <[email protected]>
Subject: [c-prog] Help with SWITCH statement
To: [email protected]
Date: Thursday, June 18, 2009, 7:56 PM











    
            
            


      
      

Hello,



I need help in understanding the switch statement in C.



Why does the following code either display 'RED' or 'WHITE' when I enter 

'r' or 'w'?



#include <stdio.h>

#include <ctype.h>



int main(void)



{

     char choice;

     switch (choice = getchar()) {

     case 'r':



case 'R':

         printf("RED" );

         break;



case 'w':



case 'W':

         printf("WHITE" );

         break;

     }



}



Should it not only output 'RED' or 'WHITE' when you enter 'R' or 'W'?



Thanks,

--ayyaz




 

      

    
    
        
         
        
        








        


        
        


      

[Non-text portions of this message have been removed]

Reply via email to