Hello i am very very beginner lvl programmer, how can i make program choose random word? Teacher asked to store words from file into dynamic array? I have tried everything and literally nothing works or is too complicated to understand. Below is simplified program.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/* file.txt looks like this:
5
HELLO
BYE
MORNING
HEY
GOOD
*/
void ReadFile() {
ifstream input("file.txt");
if (input.fail()) {
cout << "Something went wrong." << endl;
input.close();
} else {
cout << "Poggers" << endl;
}
}
void ChooseRandomWord() {
//HOW can i now make program choose a random word from file.txt ChooseRandomWord
}
int main() {
ReadFile();
ChooseRandomWord();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire