Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string question;
- std::cout << "Ask me any question and I'll give you an answer!" << std::endl;
- std::cout << "Enter you question: ";
- std::cin.ignore('n');
- std::getline(std::cin, question);
- return question.size();
- std::string allAnswers[10] = { //all the answers that will be wrote to the file
- "This line wont be read", // index 0
- "I'm not sure, but I think you will find the answer in Chapter #.",
- "That's a good question.",
- "If I were you, I would not worry about such things.",
- "That question has puzzled philosophers for centuries.",
- "I don't know. I'm just a machine.",
- "The answer is 42.",
- "Think about it and the answer will come to you.",
- "I used to know the answer to that question, but I've forgotten it.",
- "The answer can be found in a secret place in the woods."
- };
- outFilePar.open("answers.dat");
- if (outFilePar.fail()) {
- std::cout << "Output file failed to open...nTerminating program"
- << std::endl;
- exit(1);
- }
- for (std::string answer : allAnswers) {
- outFilePar << answer << "n";
- }
- outFilePar.close();
- std::string answerToQuestions[10];
- int whichAnswer = (numOfCharsPar % 9) + 1;
- inFilePar.open("answers.dat");
- if (inFilePar.fail()) {
- std::cout << "Input file failed to open...nTerminating program" <<
- std::endl;
- exit(1);
- }
- for (unsigned int i = 0; i < 9; i++) {
- std::getline(inFilePar, answerToQuestions[i]);
- }
- inFilePar.close();
- if (whichAnswer == 1) {
- std::srand(std::time(NULL));
- answerToQuestions[1] = "I'm not sure, but I think you will find the
- answer in Chapter ";
- std::cout << "n" << answerToQuestions[1] << std::rand() % 24 + 1 <<
- "." << std::endl;
- return;
- }
- else {
- std::cout << "n" << answerToQuestions[whichAnswer] << std::endl;
- }
- }
Add Comment
Please, Sign In to add comment