My code:
std::string word = "";
std::string letterAmount = "";
std::string descriptionWord = "";
if (file2.is_open()) {
std::getline(file2, line);
int commaCount = 0;
for (int i = 0; i < line.length(); i++) {
std::cout << "line: " << line[i] << std::endl;
if (line[i] == ',') {
commaCount++;
} else {
if (commaCount == 0) {
word += line[i];
} else if (commaCount == 1) {
letterAmount += line[i];
} else if (commaCount == 2) {
if (line[i] != '$') {
descriptionWord += line[i];
}
}
}
}
SimonSaysText->label("The " + letterAmount +
" letter word I am thinking of is\n " +
descriptionWord);
file2.close();
std::cout << "2" << line << std::endl;
}
Ok so I have this lab due in a week and I want my code to grab a random line from my file but the lines are like this
Rain,4,Water falling from the sky.$
Book,4,A set of written or printed pages.$
Tree,4,A tall plant with branches and leaves.$
I want my code to grab a random line from one these three using the "descriptionWord" and "letterAmount " as hints for the user so when the user puts their answer in the input box it should match with the "word"