little problem

This is a discussion on little problem within the C++ Programming forums, part of the General Programming Boards category; hi i'm making a console hangman game my problem is that i cant show the results after each user input ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    little problem

    hi
    i'm making a console hangman game
    my problem is that i cant show the results after each user input

    anyone know how this is done?



    Code:
    #include <string>
    #include <memory.h>
    #include <conio.h>
    
    
    int main()
    {
    
    char string[30]="program";
    char *pointer1=string;
    char temp[30]="       \0";
    char *pointer2=temp;
    char ansver;
    
     for(cin>>ansver;ansver!='q';cin>>ansver)
    
     for(int i=0;i<strlen(string);i++)
     {
    
     if(pointer1[i]==ansver)
     {
      pointer2[i]=pointer1[i];
      }
     }
    
    
     cout<<"result:  "<<temp; // if i would try this up in the loop
                                             //it would just show the result several 
                                             //times 
    
      system("pause");
      return 0;
      }

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    it looks like you only accept one letter for the entire app. looks like you need to put this whole thing inside a big loop where you accept a bunch of letters.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    Why make your code so inefficent and complicated when all your doing is getting performing simple input and output commands.

    Code:
    #include <stdio.h>
    
    #define STR_LEN 30
    
    int main()
    {
      char InString[STR_LEN];
    
      printf("Please enter something: ");
      gets(InString);
    
      printf("You entered: %s", InString);
    
      getchar();
      return 0;
    }
    Be a leader and not a follower.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    oh jeez I see what you did. You did make an input loop but didn't include the cout in the loop. One word.... brackets
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    ****

    the reason i send the code was that YOU people would be able to compile and run it for your selves and not come with some
    stupid replies whitout even having a look at the code

    and subdene u really think that was what i wanted to achieve?

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    I have know idea what you were really trying to achieve, unless you wanted some practice with pointers. It just seemed to me that you were over complicating the problem...... chill.
    Be a leader and not a follower.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    welll have u tried to run it yourself, perhaps then u will find out

    i COULD coment and explain every part of my code
    but i thought its not much and people will probably find out themselves

    so u solved my problem??

    lol

  8. #8
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    well to be honest, i've got a bit of headache and seeing all them stars made it worse.
    Be a leader and not a follower.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    it's ok i sovled the problem cant believe i didnt think of it
    anyway sorry bout the stars, hehe

  10. #10
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    oh whatever, i was just trying to show someone a different way of coding something.
    Be a leader and not a follower.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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