Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- enum fields {WORD, HINT, NUM_FIELDS};
- const int NUM_WORDS = 20;
- const int MAX_GUESSES = 5;
- const string WORDS[NUM_WORDS][NUM_FIELDS] =
- {
- {"computer", "It collects data, processes, and produces information"},
- {"personalcomputer", "It is a computer where you can use it at home"},
- {"gameconsole", "PS4 and Xbox"},
- {"server", "Provides a centralized storage area for programs, data, and information"},
- {"mainframe", "It can handle hundreds or thousands of connected users simultaneously"},
- {"supercomputer", "It is capable of processing more than one quadrillion instructions in a single second"},
- {"embeddedcomputer", "It is hidden inside a product that helps it automate"},
- {"abacus", "Beads on rods to count and calculate still widely used in Asia"},
- {"sliderule", "Based on Napier's rules for logarithms"},
- {"jacquardloom", "Produces patterns as brocade, damask and matelassé"},
- {"vacuumtubes", "Has no air inside of them, which protects the circuitry"},
- {"UNIVAC", "Released in 1951 and 1952 when first developed by J. Presper Eckert and John Mauchly"},
- {"gracehopper", "Recipient of Computer Science’s first “Man of the Year Award"},
- {"transistors", "They were smaller than vacuum tubes and allowed computers to be smaller in size, faster in speed, and cheaper to build"},
- {"integratedcircuits", "It is the third generation (1964-1971) computer"},
- {"microprocessor", "More commonly known as a CPU"},
- {"artificialintelligence", "The fifth generation (2010-present) of computers"},
- {"greencomputing", "Recycling and regulating manufacturing processes"},
- {"software", "Also called a program"},
- {"installing", "The process of setting up software to work with the computer, printer, and other hardware"},
- };
- string guess;
- int points = 0;
- char another;
- do
- {
- system("cls");
- srand(time(0));
- int choice = (rand() % NUM_WORDS);
- string theWord = WORDS[choice][WORD]; // word to guess
- string theHint = WORDS[choice][HINT]; // hint for word
- string jumble = theWord; // jumbled version of word
- int length = jumble.size();
- for (int i=0; i<length; ++i)
- {
- int index1 = (rand() % length);
- int index2 = (rand() % length);
- char temp = jumble[index1];
- jumble[index1] = jumble[index2];
- jumble[index2] = temp;
- }
- cout << "\n";
- cout << "========== Welcome to Word Jumble! ==========\n";
- cout << "______________________________________________\n\n";
- cout << "(Answer with lowercase letters and no spaces!)\n";
- cout << "Unscramble the letters to make a word.\n";
- cout << "Enter 'hint' for a hint.\n";
- cout << "Enter 'quit' to quit the game.\n\n";
- cout << "______________________________________________\n\n";
- cout << "The jumbled word is: " << jumble;
- for(int nIndex = 0; nIndex < MAX_GUESSES; nIndex++)
- {
- cout << "\n\nGuess " << nIndex+1 << ": ";
- cin >> guess;
- if (guess == "hint")
- {
- cout << theHint;
- points--; //subtract 1 point
- }//end if
- else if (guess == theWord)
- {
- cout << "\nThat's it! You guessed it!\n";
- points += guess.size(); //points = # of letters in word
- break;
- }//end else if
- else if (guess == "quit") // quit the game
- {
- return 0;
- }
- else
- {
- cout << "Sorry, that's not it.";
- }//end else
- }//end for
- cout << "\n\nYour Total Pvoints Are: " << points;
- cout << "\n\n\nWould You Like To Play Again? (y/n): ";
- cin >> another;
- }while(another == 'y' || another == 'Y');
- system("cls");
- cout << "Thanks for playing!";
- return 0;
- }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement