Advertisement
daniltomashi

Untitled

Dec 10th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <cstdlib>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main(){
  11. enum fields {WORD, HINT, NUM_FIELDS};
  12. const int NUM_WORDS = 5;
  13. const string WORDS [NUM_WORDS][NUM_FIELDS] = // WORDS[5][2]
  14. {
  15. {"Danil", "it's my name"},
  16. {"Bogdan", "name of my friend"},
  17. {"Oksana", "name of my mother"},
  18. {"Sasha", "name of my father"},
  19. {"Eugen", "name of my brother"}
  20. };
  21. srand(static_cast<unsigned int>(time(0))); // эта строка для того, чтобы был рандом разный при каждом новом запуске
  22. int choise = (rand() % NUM_WORDS);
  23. string theWord = WORDS[choise][WORD]; // слово, которое нужно отгадать
  24. string theHint = WORDS[choise][HINT]; // подсказка, для слова
  25.  
  26. string jumble = theWord;
  27. int length = jumble.size();
  28. for(int i = 0; i < length; i++)
  29. {
  30. int index1 = (rand() % length);
  31. int index2 = (rand() % length);
  32. char temp = jumble[index1];
  33. jumble[index1] = jumble[index2];
  34. jumble[index2] = temp;
  35. }
  36.  
  37. cout << "\t\t\tWelcome to Word Jumble!\n\n";
  38. cout << "Unscrambl е the letters to make а word. \n";
  39. cout << "Enter 'hint' for а hi nt. \n";
  40. cout << "Enter 'quit' to quit the game. \n\n";
  41. cout << "The jumble is: " << jumble;
  42. string guess;
  43. cout << "\n\nYour guess: ";
  44. cin >> guess;
  45.  
  46. int minus_score = -2;
  47.  
  48. while((guess != theWord) && (guess != "quit"))
  49. {
  50. if (guess == "hint")
  51. {
  52. cout << theHint;
  53. cout << "\nYour score is: " << minus_score << "\n";
  54. cin >> guess;
  55. cout << "\nYour score is: " << theWord.size() + minus_score;
  56. }else
  57. {
  58. cout << "Sorry, but it's not this";
  59. }
  60. cout << "\nYour guess: ";
  61. cin >> guess;
  62. }
  63.  
  64. if(guess == "quit")
  65. {
  66. cout << "\nLooser";
  67. }
  68. else if(guess == theWord)
  69. {
  70. cout << "\nWow it's impossible";
  71. cout << "\nYour score is: " << theWord.size();
  72. }
  73. cout << "\nThank you for playing";
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement