Guest User

Untitled

a guest
Oct 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. std::string question;
  2.  
  3. std::cout << "Ask me any question and I'll give you an answer!" << std::endl;
  4.  
  5. std::cout << "Enter you question: ";
  6.  
  7. std::cin.ignore('n');
  8. std::getline(std::cin, question);
  9. return question.size();
  10.  
  11. std::string allAnswers[10] = { //all the answers that will be wrote to the file
  12. "This line wont be read", // index 0
  13. "I'm not sure, but I think you will find the answer in Chapter #.",
  14. "That's a good question.",
  15. "If I were you, I would not worry about such things.",
  16. "That question has puzzled philosophers for centuries.",
  17. "I don't know. I'm just a machine.",
  18. "The answer is 42.",
  19. "Think about it and the answer will come to you.",
  20. "I used to know the answer to that question, but I've forgotten it.",
  21. "The answer can be found in a secret place in the woods."
  22. };
  23.  
  24. outFilePar.open("answers.dat");
  25. if (outFilePar.fail()) {
  26. std::cout << "Output file failed to open...nTerminating program"
  27. << std::endl;
  28. exit(1);
  29. }
  30.  
  31. for (std::string answer : allAnswers) {
  32. outFilePar << answer << "n";
  33. }
  34. outFilePar.close();
  35.  
  36. std::string answerToQuestions[10];
  37. int whichAnswer = (numOfCharsPar % 9) + 1;
  38. inFilePar.open("answers.dat");
  39. if (inFilePar.fail()) {
  40. std::cout << "Input file failed to open...nTerminating program" <<
  41. std::endl;
  42. exit(1);
  43. }
  44. for (unsigned int i = 0; i < 9; i++) {
  45. std::getline(inFilePar, answerToQuestions[i]);
  46. }
  47. inFilePar.close();
  48.  
  49. if (whichAnswer == 1) {
  50. std::srand(std::time(NULL));
  51. answerToQuestions[1] = "I'm not sure, but I think you will find the
  52. answer in Chapter ";
  53. std::cout << "n" << answerToQuestions[1] << std::rand() % 24 + 1 <<
  54. "." << std::endl;
  55. return;
  56. }
  57. else {
  58. std::cout << "n" << answerToQuestions[whichAnswer] << std::endl;
  59. }
  60. }
Add Comment
Please, Sign In to add comment