Need some help:(

This is a discussion on Need some help:( within the C++ Programming forums, part of the General Programming Boards category; Code: for(;;) { if(gender =='F') { Sleep(2000); system("cls"); //Old man says players gender size=strlen(oldman1); for(x=0;x<size;x++) { Sleep(50); printf("%c",oldman1[x]); } size=strlen(daughter); ...

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

    Need some help:(

    Code:
    for(;;)
       {
           if(gender =='F')
           {
              Sleep(2000);
              system("cls"); //Old man says players gender
              size=strlen(oldman1); 
              for(x=0;x<size;x++) 
              {   
                Sleep(50);  
                printf("%c",oldman1[x]);
                
              }
               size=strlen(daughter);
                for(x=0;x<size;x++)          
                {
                    printf("%c",daughter[x]);
                    Sleep(50);                 
                }  
                break;                                     
           }
           else if(gender =='M')
           {
              Sleep(2000);
              system("cls"); //Old man says players gender
              size=strlen(oldman1); 
              for(x=0;x<size;x++) 
              {   
                 Sleep(50);  
                 printf("%c",oldman1[x]);
                
              }
              size=strlen(son);
                for(x=0;x<size;x++)          
                {
                    printf("%c",son[x]);
                    Sleep(50);                 
                } 
                break;
           }
       }
      size=strlen(oldman2); 
      for(x=0;x<size;x++) 
      {   
           Sleep(50);  
           printf("%c",oldman2[x]); 
      }
    For some reason it only says the first 3 letters on the oldman char string and goes to the next one
    Last edited by Nathan the noob; 02-08-2009 at 10:32 PM.

  2. #2
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Nvm fixed

  3. #3
    Registered User QuestionKing's Avatar
    Join Date
    Jan 2009
    Posts
    68
    Well there areas of code not posted which could cause that. For example you are using the length of 'oldman1' to run your loop, at the time the loop is ran, what is the value of 'oldman1'...?

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    3,800
    Code:
              size=strlen(oldman1); 
              for(x=0;x<size;x++) 
              {   
                Sleep(50);  
                printf("%c",oldman1[x]);
              }
    Code:
                size=strlen(daughter);
                for(x=0;x<size;x++)          
                {
                    printf("%c",daughter[x]);
                    Sleep(50);                 
                }
    Code:
              size=strlen(oldman1); 
              for(x=0;x<size;x++) 
              {   
                 Sleep(50);  
                 printf("%c",oldman1[x]);
              }
    Code:
                size=strlen(son);
                for(x=0;x<size;x++)          
                {
                    printf("%c",son[x]);
                    Sleep(50);                 
                }
    Code:
      size=strlen(oldman2); 
      for(x=0;x<size;x++) 
      {   
           Sleep(50);  
           printf("%c",oldman2[x]); 
      }
    Seriously?! O_o

    Don't you think that just maybe that deserves a function unto itself? O_o

    Even something casually dangerous would be better than writing nearly the same thing over and over.

    Soma

    Code:
    int slowprintf
    (
       unsigned int msdelay_f,
       const char * format_f,
       ...
    )
    {
       char message_buffer[1024];
       char * character = message_buffer;
       int characters_written;
       va_list vargs;
       if(0 == format_f)
       {
          return(-1);
       }
       va_start(vargs, format_f);
       characters_written = vsprintf(message_buffer, format_f, vargs);
       if(0 < characters_written)
       {
          while(0 != *character)
          {
             fputc(*character, stdout);
             mydelay(msdelay_f);
             ++character;
          }
       }
       va_end(vargs);
       return(characters_written);
    }

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    And why is this on C++?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21