Again, in need of help.

So here I am again, first off I wanted to say thank you to the people who helped me before but now I ran into another problem. Which involves me getting a word of which I want to mask (cover) so a user can't see the word. Overall this is for a hangman game I'm working on for class of which I really have no idea of doing. Anyway if someone is willing to give me some advice, it will be greatly appreciated.

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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;

int main()
{
	
	unsigned seed = time(0); //Gets the system time
	int y = 1; // sets y as a int value type
	srand(seed); // Seed the random number generator
	
	string word;
	int random;
	char letter;
	
	fstream inputFile;
	inputFile.open("genwords.txt", ios::in);
	
	cout << "Welcome to Hangman\n" << "Below this line is your random number please enter it it when prompted\n" << endl;
	
	const int MIN_VALUE = 1; 
	const int MAX_VALUE = 100;
	y = (rand() % (MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE; // Limits the range of random numbers to be
														   // 1 -100
	cout << y << "\n" << endl; //couts the random number

	
	
	cout << "Please re-enter your number" << endl;
	
	cin >> random; // asks the user to enter their number
	
	int num = y;  // this is the line we want
        
    ifstream fin("genwords.txt");
    string line;
	int count = 0;
    
    while (getline(fin, line) && ++count < num)
        ;  // empty loop body 

    if (fin)
        cout << "line number " << num << ":\n" << "*Your word*" << endl; // "line" is the output word
    else
        cout << "file read error" << endl;
	
	cout << line << endl; // "line" is the output word
	
	cout << "Enter a letter";
	cin >> letter;
	
	if (letter != line)
		cout << "wrong choice";
	else
		cout << "Correct choice";
	
	
	inputFile.close();
		
	system("pause");
	return 0;
}
Lines 31-33: Why do you ask the user to reenter the random number? What purpose does that serve?

Line 47: If you have a read error, you probably want to exit the program rather than continuing.

Line 54: You're comparing a character (letter) to a string (line). That's legal, but not what you want. You want to determine if letter occurs one or more times in line. You also want to keep track of which characters in the word have been unmasked.

It's so the program can grab a line from a file and cout it to the program, line 47 is not a problem and as for line 54 I was trying to figure how to mask the characters. My apologies for not being specific.
Topic archived. No new replies allowed.