I'm having a hard time generating a "secret word" that is random. I'm taking a random word from the wordList array, and using it in the playOneRound function.
Here is part of my instructions:
Using wordList[wordnum] as the secret word, this function
plays one round of the game. It returns the score for that round.
In the transcript above, this function is responsible for this much
of the round 1 output, no more, no less:
Probe: assert
3
Probe: xyzzy
I don't know that word
Probe: bred
2
Probe: mucus
0
Probe: never
4
Probe: raven
Your program must call this function to play each round of the game.
and here is what I have so far: (it is very wrong)
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <ctime>
using namespace std;
void fillWords(char words[][MAXWORDLENGTH + 1], int maxwords, int& num);
int playOneRound (int wordnum);
const int MAXWORDS = 8000;
const int MAXWORDLENGTH = 6;
const int MINWORDLENGTH = 4;
char wordList [MAXWORDS][MAXWORDLENGTH + 1];
void fillWords(char words[][MAXWORDLENGTH+1], int maxwords, int& num)
{
ifstream wordfile("Z:/words.txt");
if ( ! wordfile)
{
cout << "Cannot open words.txt!" << endl;
exit(1);
}
char line[10000];
num = 0;
while (wordfile.getline(line, 10000))
{
if (num == maxwords)
{
cout << "Using only the first " << num
<< " words from words.txt" << endl;
break;
}
int k;
for (k = 0; islower(line[k]); k++)
;
if (line[k] == '\0' && k >= MINWORDLENGTH && k <= MAXWORDLENGTH)
{
strcpy(words[num], line);
num++;
}
}
}
// choose a secret word
// check if secret word is in wordList
// if in, type in a guess
// count # of correct characters in guess
int playOneRound (int wordnum)
{
for (int k = 0; k < wordnum; k++)
{
int random = rand();
char answer[MAXWORDS];
char wordList [random] = answer;
cout << "Probe:";
cin >> // guess;
if (strcpy (answer , guess ) == 0)
break;
else
// count number of correct characters
}
}
int main ()
{
int rounds;
cout << "How many rounds do you want to play?" << endl;
cin >> rounds >> endl;
for (int i=1, i < rounds +1; i++)
{
cout << "Round" << i << endl;
}