Basically I have a text file called words. I'm supposed to extract a word randomly from the file and have the user guess the word according to the definition.
I'm having trouble matching the definition to the word from the text file.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main(){
int number;
int count = 0;
string word;
string definition;
ifstream inFile;
inFile.open("words.txt");
srand(time(0));
number = rand() % 10 + 1;
for (int i = 0; i < number; i++)
{
getline(inFile, word, '#'); //extracts the word according to the random number
inFile.ignore(1000, '\n');
}
cout << definition << endl;
cout << word << endl;
system("pause");
return 0;
}
Here is my text file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet