I don't know C++, but here's a C solution.
http://ideone.com/nwIobI
#include <stdio.h>
const int NUM_GUESSES = 7;
const char SECRET[] = "hi";
#define F 0
#define T 1
const int asdf[3][256] =
{
{
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
1, T, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0
},
{
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 1, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0
},
{
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
1, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F
}
};
int main()
{
char answer[] = "__";
unsigned int hehehe = 0;
for (int i = 0; i < NUM_GUESSES; ++i)
{
printf("Enter a letter. %s\n", answer);
char guess = getchar();
getchar();
if(asdf[hehehe][guess])
{
int efef = (guess - SECRET[0]);
answer[efef] = SECRET[efef];
hehehe |= (1 << efef);
}
else
{
printf("Letter not found, try again\n");
}
if (hehehe == 3)
{
printf("You win\n");
break;
}
}
printf("The word was %s\n", SECRET);
return 0;
}