Thread: Need some help

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    Need some help

    Code:
     system("cls"); //Old man says players gender
      size=strlen(oldman1); 
      for(x=0;x<size;x++) 
      {   
           Sleep(50);  
           printf("%c",oldman1[x]);
           if(gender ='F')
           {
                     size=strlen(daughter);
                     for(x=0;x<size;x++) 
                     {
                          printf("%c",daughter[x]);
                          Sleep(50);                 
                     }                                       
           }
           else if(gender ='M')
           {
                     size=strlen(son);
                     for(x=0;x<size;x++) 
                     {
                          printf("%c",son[x]);
                          Sleep(50);
                     }
           }
      }
      size=strlen(oldman2); 
      for(x=0;x<size;x++) 
      {   
           Sleep(50);  
           printf("%c",oldman2[x]); 
      }
    For some reason no matter wat Gender = it always choose daughter

  2. #2
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    = is an assignment operator
    == is a comparison operator

    Code:
    if(x=1)
    will set the value of x to 1
    Code:
    if(x==1)
    will compare the value of x to 1

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Ya its spose to asign x to be 0
    oh yeh i see
    Last edited by Nathan the noob; 02-08-2009 at 11:24 PM.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Read what has been offered!

    Soma

  5. #5
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    Quote Originally Posted by Nathan the noob View Post
    Ya its spose to asign x to be 0
    I was actually talking about another part of your code, specifically:
    Code:
    if(gender ='F')
    This is what happens:
    if is ran into.... and then evaluate the expression (gender = 'F')
    at this point, gender holds the value 'F', a non-zero value, in other words a TRUE value which the if accepts as the final evaluation of (gender = 'F') causing that portion of code to execute, and never reach the else if below

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Yah i just noticed that

Popular pages Recent additions subscribe to a feed