Can anyone tell me what my major malfunction is here? I want to add other functionality to this program so I decided I might as well use classes and that got me about as far as this
Code:
#include <iostream>
#include "string.h"
using namespace std;
class wordtbg { // word to be guessed by player
string wordtobeguessed; // string to hold word to be guessed
char letterguess; //to hold letter that player guesses is in the wordtobeguessed
public:
string wtbg (string x); //constructor to get the wordtobeguessed
char guessfunc (char x); // function to see if letter guessed is correct or not
} hangman; //object of class wordtbg
string wordtbg::wtbg (string x)
{
wordtobeguessed = x;
}
char wordtbg::guessfunc (char x)
{
char wtbg; //will be used to turn wordtobeguessed from a string to a char type
char thing[5]; //letter guessed
string compare;
do{
for (int i = 0; i < 5; i++)
{
if ( wordtobeguessed[i] == x)
{
thing[i] = x;
compare = thing;
cout << "you guessed " << thing << " which is one of the letters!";
}
else
{
cout << "that's not one of the letters!";
}
}
} while (compare != wordtobeguessed);
}
int main ()
{
hangman.wtbg ("tulip");
char letter;
cout << "please enter a letter: ";
cin >> letter;
hangman.guessfunc (letter);
return 0;
}
everything compiles but when i try to run the program it just hangs and crashes. Incredibly simple and yet... I can't figure out the problem!