Given a file of words, \'words.txt\', the program should first pick a word at ra
ID: 3655922 • Letter: G
Question
Given a file of words, 'words.txt', the program should first pick a word at random and print it to the screen. Then the player starts guessing letters of the word. After each guess the program tells the player how many times that letter appears in the word, and prints it to the screen with all the letters that the player has guessed so far filled in. The game ends when the player guesses every letter in the word or the player makes ten incorrect guesses.
//
//
The first line of the file has a number telling you how many words there are in the file. The words are separated either by a space or a new line. This information will be very useful when you are trying to pick out a random word from the list.
//
Here is the file:
words.txt:::::
Explanation / Answer
/*you may also download the code from.....http://www.2shared.com/file/BtjJV7r7/FILE.html*/ #include#include#include#include#include void main() { ifstream fin; char data[40]; char finalData[20]; int random; int count; int length; int k,j,i=0; char guess[100]; int flag=0; int occuranceGuess=0; int incorrectGuess=0; int statusForincorrect=0; clrscr(); fin.open("words.txt",ios::in); fin>>length; random=rand()%length+1; count=1; while(!fin.eof()) { fin>>data; if(count==random) strcpy(finalData,data); count++; } coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.