Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. enum fields {WORD, HINT, NUM_FIELDS};
  11. const int NUM_WORDS = 20;
  12. const int MAX_GUESSES = 5;
  13. const string WORDS[NUM_WORDS][NUM_FIELDS] =
  14. {
  15. {"computer", "It collects data, processes, and produces information"},
  16. {"personalcomputer", "It is a computer where you can use it at home"},
  17. {"gameconsole", "PS4 and Xbox"},
  18. {"server", "Provides a centralized storage area for programs, data, and information"},
  19. {"mainframe", "It can handle hundreds or thousands of connected users simultaneously"},
  20. {"supercomputer", "It is capable of processing more than one quadrillion instructions in a single second"},
  21. {"embeddedcomputer", "It is hidden inside a product that helps it automate"},
  22. {"abacus", "Beads on rods to count and calculate still widely used in Asia"},
  23. {"sliderule", "Based on Napier's rules for logarithms"},
  24. {"jacquardloom", "Produces patterns as brocade, damask and matelassé"},
  25. {"vacuumtubes", "Has no air inside of them, which protects the circuitry"},
  26. {"UNIVAC", "Released in 1951 and 1952 when first developed by J. Presper Eckert and John Mauchly"},
  27. {"gracehopper", "Recipient of Computer Science’s first “Man of the Year Award"},
  28. {"transistors", "They were smaller than vacuum tubes and allowed computers to be smaller in size, faster in speed, and cheaper to build"},
  29. {"integratedcircuits", "It is the third generation (1964-1971) computer"},
  30. {"microprocessor", "More commonly known as a CPU"},
  31. {"artificialintelligence", "The fifth generation (2010-present) of computers"},
  32. {"greencomputing", "Recycling and regulating manufacturing processes"},
  33. {"software", "Also called a program"},
  34. {"installing", "The process of setting up software to work with the computer, printer, and other hardware"},
  35. };
  36.  
  37.  
  38. string guess;
  39. int points = 0;
  40. char another;
  41.  
  42.  
  43. do
  44. {
  45. system("cls");
  46. srand(time(0));
  47. int choice = (rand() % NUM_WORDS);
  48. string theWord = WORDS[choice][WORD]; // word to guess
  49. string theHint = WORDS[choice][HINT]; // hint for word
  50.  
  51. string jumble = theWord; // jumbled version of word
  52. int length = jumble.size();
  53.  
  54. for (int i=0; i<length; ++i)
  55. {
  56. int index1 = (rand() % length);
  57. int index2 = (rand() % length);
  58. char temp = jumble[index1];
  59. jumble[index1] = jumble[index2];
  60. jumble[index2] = temp;
  61. }
  62. cout << "\n";
  63. cout << "========== Welcome to Word Jumble! ==========\n";
  64. cout << "______________________________________________\n\n";
  65. cout << "(Answer with lowercase letters and no spaces!)\n";
  66. cout << "Unscramble the letters to make a word.\n";
  67. cout << "Enter 'hint' for a hint.\n";
  68. cout << "Enter 'quit' to quit the game.\n\n";
  69. cout << "______________________________________________\n\n";
  70. cout << "The jumbled word is: " << jumble;
  71.  
  72. for(int nIndex = 0; nIndex < MAX_GUESSES; nIndex++)
  73. {
  74. cout << "\n\nGuess " << nIndex+1 << ": ";
  75. cin >> guess;
  76.  
  77. if (guess == "hint")
  78. {
  79. cout << theHint;
  80. points--; //subtract 1 point
  81. }//end if
  82. else if (guess == theWord)
  83. {
  84. cout << "\nThat's it! You guessed it!\n";
  85. points += guess.size(); //points = # of letters in word
  86. break;
  87. }//end else if
  88. else if (guess == "quit") // quit the game
  89. {
  90. return 0;
  91. }
  92. else
  93. {
  94. cout << "Sorry, that's not it.";
  95. }//end else
  96. }//end for
  97. cout << "\n\nYour Total Pvoints Are: " << points;
  98. cout << "\n\n\nWould You Like To Play Again? (y/n): ";
  99. cin >> another;
  100. }while(another == 'y' || another == 'Y');
  101.  
  102. system("cls");
  103. cout << "Thanks for playing!";
  104.  
  105. return 0;
  106. }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement