I am writing a simple (extremely simple) hangman program. Basically the user inputs a word, then they have double the number of letters in the word for guesses (for instance if the word has 7 letters they get 14 guesses). Please don't ask why I want the user to input the word, because it is a homework assignment and that is what the instructor is wanting us to do.

I am having a problem getting the strlen() to write the value to another variable so that I can double it to get the # of guesses and also get one "_" per letter.

// A simple little hangman type game
//
//included libraries
#include <iostream>
#include <stdlib>
#include <conio>
#include <stdio>
#include <fstream>
#include <string>

using namespace std;
// begin program
void main()
{
    char getWord[256]; // variable for the inital word
    int numLetters; //variable for the number of letters in the word
    
    cout << "Welcome to the hangman program"<<endl;
    cout <<"\n Please enter a word" << endl;
    cin >>getWord;
    strlen(getWord);
    printf ("The word entered has %u letters.\n",strlen(getWord));
    strlen(getWord)=numLetters;
    while(numLetters > 0)
    {
    cout << "_";
    numLetters--;
    }
}

edit: I forgot to mention I am using Borland compiler 5.5 and I am getting the following error:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hangman1.cpp:
Error E2277 hangman1.cpp 23: Lvalue required in function main()
*** 1 errors in Compile ***

If you're using C++, you should probably be using the std::string type rather than C-style strings (char*).

And your line strlen(getWord) = numLetters; is backwards. Try flipping it around. ;)

Thanks Infarction. it fixed it. I modified code based on your suggestions as such:

// A simple little hangman type game
//
//included libraries
#include <iostream>
#include <stdlib>
#include <conio>
#include <stdio>
#include <fstream>
#include <string>

using namespace std;
// begin program
void main()
{
    string getWord; // variable for the inital word
    int numLetters; //variable for the number of letters in the word
    
    cout << "Welcome to the hangman program"<<endl;
    cout <<"\n Please enter a word" << endl;
    cin >>getWord;
    getWord.length();
    printf ("The word entered has %u letters.\n",getWord.length());
    numLetters=getWord.length();
    while(numLetters > 0)
    {
    cout << "_ ";
    numLetters--;
    }
}

>getWord.length();
This line doesn't do anything.

And a couple of other things: change "void main" to "int main" and get rid of <conio>.

Hello frens

I m a bit new to programming in C++, but still from what i understood this is a pretty good program. Keep posting such programs they will help newbies like me to understand the programming tricks.

As my small contribution i suggets a site www.ITpalace.com , this is a quite informative site and will provide you some interactions regarding programming.

Bye
Soha

Ok, now I am having issues with more sections of code. The first I am trying to create a function that will take getWord.length() and will output the "_" one for each letter remaining. So if the word is say "hippo" and you guess "p" it would look like _ _ pp_.

// A simple little hangman type game
//
//included libraries
#include <iostream>
#include <stdlib>
#include <stdio>
#include <fstream>
#include <string>

using namespace std;

char dashes(int);
// begin program
int main()
{
    string getWord; // variable for the inital word
    int numLetters; //variable for the number of letters in the word
    int numGuesses; //variable for the number of guesses the contestant has remaining.
    char guessLetter;//variable for the letter that the contestant guesses.
    char foundLetter; //variable for letters in the word
    char letterList[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int i;
    cout << "Welcome to the hangman program"<<endl;
    cout <<"\n Please enter a word" << endl;
    cin >>getWord;
    printf ("The word entered has %u letters.\n",getWord.length());

    numLetters=getWord.length(); // get the number of letters in the word the user input
 while(numLetters > 0) //prints out the _, one for each letter
    {
    cout << "_ ";
    numLetters--;
    }
numGuesses=getWord.length()*2; //gets the number of guesses for the inital and the remaining guesses for the contestant
    if (numGuesses == getWord.length()*2)
    {
        cout << "You have "<<numGuesses <<" guesses." <<endl;
    }
    else
    cout << "You have "<<numGuesses <<"remaining." <<endl;
    
    cout << "Guess a letter" <<endl;
    cin >> guessLetter;
    while (guessLetter != letterList[i])
    {
        cout << "Your guess was not a letter, please guess again.";
    }
    if (foundLetter = getWord.find(guessLetter))
    {
    cout << "Your guess was correct" <<endl;
    cout << guessLetter << dashes(numLetters) <<endl;

    numGuesses--;
    cout << "You have "<<numGuesses <<" remaining."<<endl;
    }
    else
    {
        numGuesses--;
        cout << "Your guess was incorrect. You have "<<numGuesses <<" remaining." <<endl;
    }
return 0;
}

char dashes()
{
 while(numLetters > 0) //prints out the _, one for each letter
    {
    cout << "_ ";
    numLetters--;
    }
}

on compile I get the following errors:

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hangman1a.cpp:
Warning W8012 hangman1a.cpp 36: Comparing signed and unsigned values in function
main()
Warning W8060 hangman1a.cpp 49: Possibly incorrect assignment in function main()

Error E2451 hangman1a.cpp 67: Undefined symbol 'numLetters' in function dashes()

Warning W8070 hangman1a.cpp 72: Function should return a value in function dashes()
*** 1 errors in Compile ***

Aside from the undefined symbol issue, my problem is that I need to call numLetters for the dashes, but at the same time I need to decrement the number of dashes by the number of letters that are displayed. I also need a method by which to display the correctly guessed letters in the correct location. So that "hippo" doesn't show up as pp_ _ _ when you guess "p". To resolve this issue would it be feasible (or possible) to change the string into a char array, or is there a better method to do this?

The string class overloads the [] operator so individual characters can be accessed just like with a char array. the c_str() method will return a const char* to the char array embedded within the string object if you want to change the string into a char [].

You could do something like this:

string displayString ;
int len = getWord.length();
for(int i = o; i < len; ++i)
displayString += "_";

now displayString has as many underscores as there are letters in getWord. And you can display what evers in displayString by something like:

cout << displayString;

then when user inputs a valid guessLetter you loop through getWord and if guessLetter equals getWord then you assign guessLetter to displayString. After loop is completed you can then just output displayString with all the correct guesses in their appropriate slots with remaining underscores intact.

I am trying to convert this

string displayString ;
int len = getWord.length();
for(int i = o; i < len; ++i)
displayString += "_";

into a function, but I cannot seem to get anything but more and more errors.
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hangman1a.cpp:
Warning W8012 hangman1a.cpp 36: Comparing signed and unsigned values in function
main()
Error E2303 hangman1a.cpp 64: Type name expected
Error E2356 hangman1a.cpp 64: Type mismatch in redeclaration of 'displayString(s
tring)'
Error E2344 hangman1a.cpp 11: Earlier declaration of 'displayString(string)'
Error E2063 hangman1a.cpp 64: Illegal initialization
Error E2293 hangman1a.cpp 64: ) expected
Error E2141 hangman1a.cpp 70: Declaration syntax error
*** 6 errors in Compile ***

Here is the code that generated the errors:

// A simple little hangman type game
//
//included libraries
#include <iostream>
#include <stdlib>
#include <stdio>
#include <fstream>
#include <string>

using namespace std;
string displayString(string); //prototype header for displayString function
// begin program
int main()
{
    string getWord; // variable for the inital word
    int numLetters; //variable for the number of letters in the word
    int numGuesses; //variable for the number of guesses the contestant has remaining.
    char guessLetter;//variable for the letter that the contestant guesses.
    char foundLetter; //variable for letters in the word
    char letterList[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int i;
    cout << "Welcome to the hangman program"<<endl;
    cout <<"\n Please enter a word" << endl;
    cin >>getWord;
    printf ("The word entered has %u letters.\n",getWord.length());
    
      // get the number of letters in the word the user input
 /*while(numLetters > 0) //prints out the _, one for each letter
    {
    cout << "_ ";
    numLetters--;
    }
*/
    cout << displayString;
numGuesses=getWord.length()*2; //gets the number of guesses for the inital and the remaining guesses for the contestant
    if (numGuesses == getWord.length()*2)
    {
        cout << "You have "<<numGuesses <<" guesses." <<endl;
    }
    else
    cout << "You have "<<numGuesses <<"remaining." <<endl;
    
    cout << "Guess a letter" <<endl;
    cin >> guessLetter;
    while (guessLetter != letterList[i])
    {
        cout << "Your guess was not a letter, please guess again.";
        break;
    }
    if (getWord.find(guessLetter))
    {
    cout << "Your guess was correct" <<endl;
    //cout << guessLetter << <<endl;
    numGuesses--;
    cout << "You have "<<numGuesses <<" remaining."<<endl;
    }
    else
    {
        numGuesses--;
        cout << "Your guess was incorrect. You have "<<numGuesses <<" remaining." <<endl;
    }
return 0;
}
displayString(&getWord)
{
    int len = getWord.length();
    for(int i = 0; i < len; ++i)
    displayString += "_";
    numLetters=getWord.length();
}

Why not have an answer string which you load with '_'s and just output that string. As correct guesses are made, replace each '_' with the letter.

ok, I have completely changed the program. I now have three components that work seperately, but not when I attempt to mesh them.
Here is the code individually. Keep in mind that each seperate function is in fact written as a seperate program and when I mesh them I do change variables a bit so that there is no multiple declarations and such. The error I get is Invalid indirection in function main().

Can someone please help direct me in the proper way to mesh these three pieces together...I was thinking creating 2 parts as header files or some such method.

I am also thinking I am not needing all three parts. Basically I am trying to create the hangman program that uses a users input (the instructor) who will then "guess" the input word, with a mix of capital and non-capital letters and have the program return the word as it is entered (that is if it is Antique it would come out as Antique, AnTiQuE would come out as AnTiQuE and so on) but as long as the letters are there in the correct order it would come out as correct. Also the number of guesses is decremented by 1 each guess. If guesses run out...you are hung. I cannot seem to mesh the parts to come out with a whole though.

This is the attempt at meshing the code:
which causes the aforementioned error

#include <iostream>
#include <string>

using namespace std;

int main()
{
    
    char getWord[50];
    char goodGuesses[256] = {'\0'};
    char badGuesses[256] = {'\0'};
    bool badGuess = true;
    char guess;
    int guessCount;
    int guessCountLimit;
    bool sameWord = true;
    int t;
    int r;
    int s;
    cout << "Please enter a word" << endl;
    cin >> getWord;
  //find length of target
        int i = 0;
    while(getWord[i] != '\0') //stop at null terminator
        i++;
    guessCountLimit = i*2;

    cout << "Guess a letter: ";
    cin >> guess;
    
    guessCount = 0;
    i = 0;
    int j = 0;
    int k = 0;
    while(guessCount <= guessCountLimit)
    {
        while(getWord[i] != '\0')
        {
            if(getWord[i] == guess)
            {
                goodGuesses[j] = guess;
                badGuess = false;
                j++; //advance position in goodGuesses
            }
            i++;
        }
        if(badGuess)
        {
            badGuesses[k] = guess;
            k++; //advance position in badGuesses
        }
        
        i = 0; //reset to go through target again
        badGuess = true;
        cout << "Good guesses: " << goodGuesses << endl;
        cout << "Bad guesses:  " << badGuesses << endl;
        
        guessCount++;
        
        //get next guess
        cout << "Guess a letter: ";
        cin >> guess;
    }
    //Load up r
    i= 0;
    while(t[i])
    {
        r[i] = '-';
        i++;
    }
    //end r with null terminator
    r[i] = '\0';
    
    cout << t << " " << r << endl;

    
    cout << "Guess: ";
    cin >> guess;
    
    i = 0;
    while(guessCount !=guessCountLimit)
    {
        while(t[i])
        {
            //cout << guess << " = " << t[i] << endl;
        
            if(guess == t[i])
                r[i] = guess;
        
            i++;
        }
        i = 0;
        
        while(sameWord && t[i])
        {
            cout << int(t[i]) << " = " << int(r[i]) << endl;
        
            if(t[i] != r[i])
                sameWord = false;
        
            i++;
        }
        
        i = 0;
        
        if(sameWord)
            break;
    
        sameWord = true;
    
    
        cout << r << endl;
        
        cout << "Guess: ";
        cin >> guess;

    }
}

Here are the 3 parts
part 1

#include <iostream>
#include <string>

using namespace std;

int main()
{
    
  char getWord[50];
    char goodGuesses[256] = {'\0'};
    char badGuesses[256] = {'\0'};
    bool badGuess = true;
    char guess;
    int guessCount;
    int guessCountLimit;
    
    cout << "Please enter a word" << endl;
    cin >> getWord;
  //find length of target
        int i = 0;
    while(getWord[i] != '\0') //stop at null terminator
        i++;
    guessCountLimit = i;

    cout << "Guess a letter: ";
    cin >> guess;
    
    guessCount = 0;
    i = 0;
    int j = 0;
    int k = 0;
    while(guessCount <= guessCountLimit)
    {
        while(getWord[i] != '\0')
        {
            if(getWord[i] == guess)
            {
                goodGuesses[j] = guess;
                badGuess = false;
                j++; //advance position in goodGuesses
            }
            i++;
        }
        if(badGuess)
        {
            badGuesses[k] = guess;
            k++; //advance position in badGuesses
        }
        
        i = 0; //reset to go through target again
        badGuess = true;
        cout << "Good guesses: " << goodGuesses << endl;
        cout << "Bad guesses:  " << badGuesses << endl;
        
        guessCount++;
        
        //get next guess
        cout << "Guess a letter: ";
        cin >> guess;
  }
}

Part 2 (compares the input "strings")

//end r with null terminator
    r[i] = '\0';
    
    cout << t << " " << r << endl;

    
    cout << "Guess: ";
    cin >> guess;
    
    i = 0;
    while(1)
    {
        while(t[i])
        {
            //cout << guess << " = " << t[i] << endl;
        
            if(guess == t[i])
                r[i] = guess;
        
            i++;
        }
        i = 0;
        
        while(sameWord && t[i])
        {
            cout << int(t[i]) << " = " << int(r[i]) << endl;
        
            if(t[i] != r[i])
                sameWord = false;
        
            i++;
        }
        
        i = 0;
        
        if(sameWord)
            break;
    
        sameWord = true;
    
    
        cout << r << endl;
        
        cout << "Guess: ";
        cin >> guess;

    }

Part 3 (makes it case insensitive)

#include <iostream>
using namespace std;

int main()
{
    char a[] = "Hello";
    char b[256];
    
    //load up b with capped a
    int i = 0;
    for( ; a[i]; i++)
    {
        b[i] = a[i];
        //cap non-capped
    
        if(b[i] > 96 && b[i] < 123)
            b[i] = b[i] - 32;
    }

    b[i] = '\0';
    
    cout << a << " " << b << endl;
    

    return 0;
}

I've reworked the full program a little bit. Note the new header file which eliminates the need for the sameWord function. Really look at and understand the use of multiple conditions in the while loop and the use of flags. The code as presented is untested and comes with no warrantees.

#include <iostream>
#include <cstring> //for functions to manipulate C style strings

using namespace std;

int main()
{
    
    char getWord[50];
    char guessString[50];
    char goodGuesses[99] = {'\0'};
    char badGuesses[99] = {'\0'};
    char guess;
    bool badGuess;
    int guessCount = 0;
    int guessCountLimit;
    
    cout << "Please enter a word" << endl;
    cin >> getWord;
     
    //place one '-' in guessString for every letter in getWord
    int i = 0;
    while(getWord[i])
    {
        guessString[i] = '-';
        i++;
    }

    //end guessWord with null terminator
    guessString[i] = '\0';
    
     
    //calculate guessCountLimit
    guessCountLimit = i * 2;

    cout << "Guess a letter: ";
    cin >> guess;

    i = 0; //keep track of where you are in getWord and guessString
    int j = 0; //keep track of goodGuesses
    int k = 0; //keep track of badGuesses

    bool incomplete = true;  //means guessString != getWord

    while(guessCount <= guessCountLimit && incomplete)
    {
        while(getWord[i] != '\0')
        {
            if(getWord[i] == guess)
            {
                guessString[i] = guess; //place correct guess in guessString
                badGuess = false; //set flag
            }

            i++; //advance position in getWord
        }
            
        if(badGuess)
        {
          badGuesses[k] = guess;
          k++; //advance position in badGuesses
        }
        else 
        {
          goodGuesses[j] = guess;
          j++; //advance position in goodGuesses
        }

        //display results so far
        cout << "Good guesses: " << goodGuesses << endl;
        cout << "Bad guesses:  " << badGuesses << endl;
        
        guessCount++; 

        //if guessString is now the same as getWord
        if(strcmp(guessString, getWord) == 0)
        {
          incomplete = false;  //change the flag variable to stop the loop
        }
        else
        {
          //put the pressure on
          cout << "you have " << guessCountLimit - guessCount << " guesses left" << endl;
          
          //get next guess
          cout << "Guess next letter: ";
          cin >> guess;

          //reset variables
          i = 0; 
          badGuess = true;
        }
    }
     
    //now why did the loop stop
    if(incomplete)
    {
      cout << "Sorry, you lost" << endl;  
    }
    else
    {
      cout << "You got it!" << endl;
      cout << "The word was: " << guessString << endl;
    }
}

why not better work it out an even more simple way... get your string's length and create an array of characters as long as the string, which will substitute your string in the rest of the program. This way you can compare your guess individually with each element in the array...

i don't know... maybe it can make things a bit more simple...

why not better work it out an even more simple way... get your string's length and create an array of characters as long as the string, which will substitute your string in the rest of the program. This way you can compare your guess individually with each element in the array...

i don't know... maybe it can make things a bit more simple...

That's about what WaltP suggested :icon_wink:

well, it's pretty near to what i said, though that gave me an idea... why not make a fusion of both ideas and create two individual arrays with the size of the string: one with '_' in each element, and another one with the letters in the string in it. When the user's guess is correct, you enter a for loop and assign the user's guess letter into the matching places in array1 (the one with '_') and array2 (the one with the letters)...

get it?

Thanks to all of you for your help. I got it!!!
Here is the final code...

#include <iostream>
#include <cstring> //for functions to manipulate C style strings

using namespace std;

int main()
{
    
    char getWord[50];
    char guessString[50];
    char goodGuesses[99] = {'\0'};
    char badGuesses[99] = {'\0'};
    char guess;
    bool badGuess = true;
    int guessCount = 0;
    int guessCountLimit;
    
    cout << "Please enter a word: ";
    cin >> getWord;
    
    system("cls");
     
    //place one '-' in guessString for every letter in getWord
    int i = 0;
    while(guessString[i] != '\0')
    {
        while(getWord[i])
        {
            guessString[i] = '-';
            i++;
        }
        guessString[i] = '\0';
        cout << "The word has " << i << " letters" << "\t"; 
        cout << guessString << endl;
    }
    //end guessWord with null terminator
    guessString[i]='\0';
  
     
    //calculate guessCountLimit
    guessCountLimit = i * 2;
    cout << "You have " << guessCountLimit <<" guesses to start." << endl;
    cout << "Guess a letter: ";
      cin >> guess;

    i = 0; //keep track of location in getWord and guessString
    int trackGood = 0; //keep track of goodGuesses
    int trackBad = 0; //keep track of badGuesses

    bool incomplete = true;  //means guessString != getWord
    
    while(guessCount < guessCountLimit && incomplete)
    {
        while(getWord[i] != '\0')
        {
            if(getWord[i] == guess)
            {
                guessString[i] = guess; //place correct guess in guessString
                badGuess = false; //set flag
            }
            
            cout << guessString[i];
            i++; //advance position in getWord
            
        }
            
        if(badGuess)
        {
          badGuesses[trackBad] = guess;
          trackBad++; //advance position in badGuesses
        }
        else 
        {
          goodGuesses[trackGood] = guess;
          trackGood++; //advance position in goodGuesses
        }

        //display results so far
        
        cout << guessString[i] << endl;
        cout << "Good guesses: " << goodGuesses << endl;
        cout << "Bad guesses:  " << badGuesses << endl;
        
        guessCount++; 

        //if guessString is now the same as getWord
        if(strcmp(guessString, getWord) == 0)
        {
          incomplete = false;  //change the flag variable to stop the loop
          break;
        }
        else if (guessCount == guessCountLimit)
            {
            break;
            }
          else
        {
          //puts the pressure on
          cout << "you have " << guessCountLimit - guessCount << " guesses left" << endl;
          
          //get next guess
          cout << "Guess next letter: ";
          cin >> guess;
          system("cls");

          //reset variables
          i = 0; 
          badGuess = true;
        }
    }
     
     
    if(incomplete)//if word is not guessed then output "Sorry you lost. the word was"
    {
      cout << "Sorry, you lost." << endl;
      cout << "The word was: " << getWord << endl;
    }
    else //if the word is guessed. 
    {
      cout << "You got it!" << endl;
      cout << "The word was: " << getWord << endl;
    }

    return 0;
}

actually this is not finished. I found out that I forgot to make it case insensitive and also I need to keep track of an alert on repeat guesses.

However the issue I am having is with case insensitivity.

I cannot seem to get it to work. The closest I can get is as follows:

#include <iostream>
#include <cstring> //for functions to manipulate C style strings

using namespace std;
bool isCap(char b)
{
    if(b > 64 && b < 91)
        return true;
    return false;
}


int main()
{
    
    char getWord[50];
    char guessString[50];
    char goodGuesses[99] = {'\0'};
    char badGuesses[99] = {'\0'};
    char temp;
    char guess;
    bool badGuess = true;
    int guessCount = 0;
    int guessCountLimit;
    char repeat;
    cout << "Please enter a mystery word: ";
    cin >> getWord;
    
    system("cls");
     
    //place one '-' in guessString for every letter in getWord
    int i = 0;
    while(guessString[i] != '\0')
    {
        while(getWord[i])
        {
            guessString[i] = '-';
            i++;
        }
        guessString[i] = '\0';
        cout << "The word has " << i << " letters" << "\t"; 
        cout << guessString << endl;
    }
    //end guessWord with null terminator
    guessString[i]='\0';
  
     
    //calculate guessCountLimit
    guessCountLimit = i * 2;
    cout << "You have " << guessCountLimit <<" guesses to start." << endl;
    cout << "Guess a letter: ";
      cin >> guess;
    
    i = 0; //keep track of location in getWord and guessString
    int trackGood = 0; //keep track of goodGuesses
    int trackBad = 0; //keep track of badGuesses
    bool incomplete = true;  //means guessString != getWord
    
    while(guessCount < guessCountLimit && incomplete)
    {
        while(getWord[i] != '\0')
        {
            if(isCap(getWord[i]) && !isCap(guess))
                guess = guess - 32;
            
            if(!isCap(getWord[i]) && isCap(guess))
                guess = guess + 32;            
                
            if(isCap(getWord[i]) == isCap(guess))
            {
                guessString[i] = guess; //place correct guess in guessString
                badGuess = false; //set flag
            }
            
            cout << guessString[i];
            i++; //advance position in getWord
            
        }
            
        if(badGuess)
        {
          badGuesses[trackBad] = guess;
          trackBad++; //advance position in badGuesses
        }
        else 
        {
          goodGuesses[trackGood] = guess;
          trackGood++; //advance position in goodGuesses
        }
        
        //display results so far
        
        cout << guessString[i] << endl;
        cout << "Good guesses: " << goodGuesses << endl;
        cout << "Bad guesses:  " << badGuesses << endl;
        
        guessCount++; 

        //if guessString is now the same as getWord
        if(strcmp(guessString, getWord) == 0)
        {
          incomplete = false;  //change the flag variable to stop the loop
          break;
        }
        else if (guessCount == guessCountLimit)
            {
            break;
            }
          else
        {
          //puts the pressure on
          cout << "you have " << guessCountLimit - guessCount << " guesses left" << endl;
          
          //get next guess
          cout << "Guess next letter: ";
          cin >> guess;
          
          system("cls");

          //reset variables
          i = 0; 
          badGuess = true;
        }
    }
     
     
    if(incomplete)//if word is not guessed then output "Sorry you lost. the word was"
    {
      cout << "Sorry, you lost." << endl;
      cout << "The word was: " << getWord << endl;
    }
    else //if the word is guessed. 
    {
      cout << "You got it!" << endl;
      cout << "The word was: " << getWord << endl;
    }

    return 0;
}

However this loads up the ____ with all the same letter for instance:
When the mystery word is "Antique" you guess "A"
and it outputs "Aaaaaaa" then you guess "n" it outputs "nnnnnnn"
and so on.

I need it to be case insensitive and at the same time I need to output characters EXACTLY as the player enters them. So if they put in AnTiQuE it comes out as such even if the word was "Antique" They need to be able to use any combination of capital and lowercase letters and have it return correct as soon as it it guessed.

Further the code above for does not return a "correct" when the word is guessed, I think it has to do with Ascii values not matching.

Any help or guidance on how to acheive the desired final results would be greatly appreciated.

this may require you to check your capital letters in a separate array...

my idea of a simple process to do this is the next one:

1.- create an array that includes all capital letters.

2.-inside a loop, compare all of the letters in the string to both arrays (capital and non-capital letters), and convert all letters in the string to non-capital letters, so that you won't have any trouble further...

3.- to make it trouble proof, compare all of the users inputs to both arrays in a loop, and convert all inputs into non-capital letters

4.- compare the input you just converted with the word you want the user to find...

this may require you to check your capital letters in a separate array...

my idea of a simple process to do this is the next one:

1.- create an array that includes all capital letters.

2.-inside a loop, compare all of the letters in the string to both arrays (capital and non-capital letters), and convert all letters in the string to non-capital letters, so that you won't have any trouble further...

3.- to make it trouble proof, compare all of the users inputs to both arrays in a loop, and convert all inputs into non-capital letters

4.- compare the input you just converted with the word you want the user to find...

actually it was much simpler than that. the issue was here

while(getWord[i] != '\0')
        {
            if(isCap(getWord[i]) && !isCap(guess))
                guess = guess - 32;
            
            if(!isCap(getWord[i]) && isCap(guess))
                guess = guess + 32;            
                
            [B]if(isCap(getWord[i]) == isCap(guess)) //changed to if(getWord[i] == guess) and it worked.
[/B]            {
                guessString[i] = guess; //place correct guess in guessString
                badGuess = false; //set flag
            }
            
            cout << guessString[i];
            i++; //advance position in getWord
            
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.