Hangman boards

This is what I have to do:
◦Indicate to the user whether or not the letter to guess was valid or invalid (case insensitive search).
◦Draw the hangman board that corresponds to the number of wrong guesses after each letter is guessed.
◦The program should keep track of the number of wrong guesses and only allow the user to keep guessing if they have not incorrectly guessed the complete hangman (6 wrong guesses = lose game).
◦The user cannot win the game yet or guess the word correctly yet.

However I can not get the boards to print at all. I figured out the case insensitive search. PLEASE HELP!!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
#include <algorithm>

using namespace std;

const string BOARD=" -------|\n |      |\n        |\n        |\n        |\n        |\n      -----\n";
const string BOARD2=" -------|\n |      |\n O      |\n        |\n        |\n        |\n      -----\n ";
const string BOARD3=" -------|\n |      |\n O      |\n |      |\n        |\n        |\n      -----\n";
const string BOARD4="  -------|\n  |      |\n  O      |\n -|      |\n         |\n         |\n      -----\n";
const string BOARD5="  -------|\n  |      |\n  O      |\n -|-     |\n         |\n         |\n      -----\n";
const string BOARD6="  -------|\n  |      |\n  O      |\n -|-     |\n /       |\n         |\n      -----\n";
const string BOARD7="  -------|\n  |      |\n  O      |\n -|-     |\n / \\     |\n         |\n      -----\n";
const int maxTries = 6;

int main()
{
	//declaration
	ifstream inFile;
	string hangman;
	char guess = 'a';
	int i = 0;
	int wrongGuesses;
	bool foundLetter = false;
	string correct;
	string incorrect;

	//input	
	inFile.open("hangman.dat");
	
	if(!inFile)
	{
		cout << "Error opening file\n";
		system("pause");
		return 1;
	}
	
	while(!inFile.eof())
	{
		inFile >> hangman;
		cout << hangman << endl;
	}
	std::transform(hangman.begin(), hangman.end(), hangman.begin(), ::toupper);
	cout << endl;
	cout << "Word from datafile: " << hangman << endl;
	cout << endl;

	inFile.close();

     int counter = 0;
    	for(wrongGuesses=0; wrongGuesses <=10; wrongGuesses++) // 6 guesses
    	{	
    		cout << "Please enter a letter to guess: ";
    		cin >> guess;
    		guess = toupper(guess);
    	
        cout << "You guessed letter " << guess << endl;
    
    	bool foundLetter = false;
        for(i=0; i < hangman.length(); i++)
        {
                 if(guess == hangman[i])
                 {
                          cout << guess << " is in the word!" << endl;
                          foundLetter = true;
                          counter++;
                 }
        }
        
        if(foundLetter)
             correct += guess;
        else
             incorrect += guess;
             
    	if(!foundLetter)
    	{
    		cout << guess << " is not in the word! Try again!!" << endl;
    		wrongGuesses++;
                           if (wrongGuesses==10)
                           {
                                            cout << "You've Guessed all wrong letters! GAME OVER" << endl;
                                            cout << endl;
                                            break;
                           }
      }
	//process
//	switch(guess)
//		{
//			case 1:
//				cout << BOARD << endl;
//				break;
//
//			case 2:
//				cout << BOARD2 << endl;
//				break;
//
//			case 3:
//				cout << BOARD3 << endl;
//				break;
//
//			case 4:
//				cout << BOARD4 << endl;
//				break;
//			case 5:
//				cout << BOARD5 << endl;
//				break;
//			case 6:
//				cout << BOARD6 << endl;
//				break;
//			case 7:
//				cout << BOARD7 << endl;
//				break;
//		}
}

	//output

	
	//cout << BOARD << endl;
//	cout << BOARD2 << endl;


	


	cout << "\n\n";
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.