Need help finishing hangman code

Here is my code:
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
//hangman
//Dylan Metz
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>

using namespace std;

//functions
//double index();
int main()
{
int const SIZE=22;
char name[20];
char dash[SIZE]={"                    "};
char q; //The User's Guess
int NumOfGuess=6; //Number of guesses
int flag;
int index1;

//Open text file called hangman.txt
ifstream myfile;
myfile.open ("hangman.txt");

myfile>>name;

//Open text file called index.txt
ofstream outputFile;
outputFile.open ("index.txt");
for (int index = 0; index<SIZE && name[index]!=' '; index++)
{
	if (toupper(name[index])>='A' && toupper(name[index])<='Z')
	{
	 dash[index]= '-' ;
	 outputFile<<index<<endl;
	}
}
//close file
outputFile.close();

for (NumOfGuess=6; NumOfGuess>0; NumOfGuess--)
{
cout<<"The Word is ";
for(int x=0;x<strlen(name);x++)
{
cout<<dash[x];
}

cout<<" "<<endl;

//Have the User make a guess
cout<<"Please make a guess: "<<endl;
cin>>q; //The User's Guess
cout<<" "<<endl;

flag=0;
//open file
ifstream myfileindex;
myfileindex.open ("index.txt");
for (int a=0; a<strlen(name); a++)
{
	if (q==name[a])
	 {
	 cout<<"Your guess was correct"<<endl;
	 cout<<" "<<endl;
	 //name[a]=dash[SIZE];
	 myfileindex>>index1;
	 name[a]=dash[index1];
	 NumOfGuess++;
	 flag=1;
	 }
myfileindex.close;
}
if (flag==0)
{
cout<<"Your guess was wrong."<<endl;
}
} //End of Guess counter



if(NumOfGuess>0)
{
cout<<"Game Over"<<endl;
cout<<"The word was "<<name<<endl;
}
else
{
cout<<"You Won"<<endl;
}


return 0;
}




My college uses hypergrade to upload our work. When I try to upload I get an error. I think it has something to do with the index in the for loop(s).

Can someone please help.

I am using a portable version of dev-c++ (orwell 5.1)

edit: I get this error:
hangman.cpp [Error] statement cannot resolve address of overloaded function (line 73

UPDATE:
I fixed it.

UPDATE 2:
okay i uploaded my work to hyper grade and it failed all the test cases.
I can I fix and improve my codr to do what the assignment asks? I really need help

Question 1

Hangman

For this assignment your are to write a program, using strings (from the string class) that plays
the popular game of Hangman. See the Wikipedia definition if
you have never played the game: http://en.wikipedia.org/wiki/Hangman_(game).

Here is how the program should work:

The word, phrase or sentence will be read in from a file. The filename will be read in from the console.
There will be only one word, phrase or sentence per file.The user guesses will be read in from the console.

(1) The program should display the line by hiding all letters (a-z, A-Z)
with a '-' (dash). All other characters should be displayed normally.
(2) The program should ask the player to make a guess.
(3) If the player makes a correct guess then the program should
redisplay the word, phrase or sentence with the letter displayed and ask
the player to make another guess
(4) If the palyer makes an incorrect guess then the program should tell
the player the guess was incorrect, subtract a guess and tell the user how
many guesses remain.
(5) If no more guesses remain then the program should print a message stating
that the game is over and displaying the original word, phrase or sentence.
(6) If more guesses remain then the program should ask the player to guess
again.
(7) The user will have a maximum of five guesses.

Last edited on
Topic archived. No new replies allowed.