Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <vector>
- #include <cmath>
- #include <cstdlib>
- #include <iomanip>
- using std::cout,std::cin,std::endl,std::string;
- string PuzzleHint(string hint, string answer) {
- hint = answer.at(0);
- cout << "\n Hint: Starts with the letter " << hint << endl;
- cout << "Your guess: ";
- return hint;
- }
- int GuessCorrectly(int score) {
- score = score+1;
- cout << "Congratulations! You got it correct. You got one point. \n ";
- cout << "Would you like to play again?(yes/no): ";
- return score;
- }
- /*
- string crossWord1() {
- }
- string crossWord2() {
- }
- string crossWord3() {
- }
- string crossWord4() {
- }
- */
- // this is not inside of loop so it is not being called to print again
- // make it a function then call that function within the loop at the
- // approate spot to print it again.
- // to do:
- // make it actually print "random" words
- // needs a bank of real words ( words stored in an array would work)
- // to be selected in a "random" form
- // then "random" letters to be printed around the word in the matrix
- // word to be randomly printed out forward, backward, and on a diangle
- //pattern.
- void random_word() {
- cout << "****************************Word Search Puzzle**************************** \n \n";
- cout << "A randomly generated puzzle is printed on the screen."
- << " The\npuzzle has a word which varies in length. If the word is\nguessed correctly"
- << " you will gain a point. \n\n\n";
- cout << "a b q g h u m e a y \n"
- << "l j e v x a f i r c \n"
- << "t v s e p g n b w k \n"
- << "n d u f n f i t i j \n"
- << "z v s r j o c w r a \n"
- << "l i m e o y m c r t \n"
- << "b r e n g q p e d j \n"
- << "s a r p n g g u l p \n"
- << "u j n q a n l k r y \n"
- << "c u w a m h w l x e \n"
- << "n d q k n r k f l q \n"
- << "q t e g n a r o u q \n\n\n";
- cout << "****************************************************************************" << endl;
- }
- int main () {
- int wordLength;
- int score;
- string userGuess;
- string userPlayAgain;
- int threeLetterWord;
- int fourLetterWord;
- int fiveLetterWord;
- int sixLetterWord;
- string answer;
- string hint;
- score = 0;
- srand (time (0));
- wordLength = rand () % (6 - 3 + 1) + 3;
- do {
- random_word();
- if (wordLength == 3) {
- cout << "Find the " << wordLength << " letter word. \n";
- threeLetterWord = rand() % 2 + 1;
- if (threeLetterWord == 2) {
- answer = "bee";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- // prevent from
- //skipping over cin
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "bee") {
- cout << endl;
- score = GuessCorrectly(score);
- cout << endl;
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- }
- if (threeLetterWord == 1) {
- answer = "ant";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "ant") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- if (wordLength == 4) {
- cout << "Find the " << wordLength << " letter word.\n";
- fourLetterWord = rand() % 2 + 1;
- if (fourLetterWord == 2) {
- answer = "kiwi";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "kiwi") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- if (fourLetterWord == 1) {
- answer = "lime";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "lime") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- }
- if (wordLength == 5) {
- cout << "Find the " << wordLength << " letter word.\n";
- fiveLetterWord = rand() % 2 + 1;
- if (fiveLetterWord == 2) {
- answer = "lemon";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "lemon") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- }
- }
- if (fiveLetterWord == 1) {
- answer = "mango";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "mango") {
- cout << endl;
- GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- }
- if (wordLength == 6) {
- cout << "Find the " << wordLength << " letter word.\n";
- sixLetterWord = rand() % 2 + 1;
- if (sixLetterWord == 2) {
- answer = "orange";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "orange") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- if (sixLetterWord == 1) {
- answer = "banana";
- cout << "Your guess(type hint for a clue): ";
- getline(cin, userGuess);
- if (userGuess == "hint") {
- PuzzleHint(hint, answer);
- cin >> userGuess;
- std::cin.ignore(10, '\n');
- }
- if (userGuess == "banana") {
- cout << endl;
- score = GuessCorrectly(score);
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- else {
- cout << "\n That was incorrect.\n"
- << "Would you like to play again(yes/no): ";
- cin >> userPlayAgain;
- cout << endl;
- std::cin.ignore(10, '\n');
- }
- }
- }
- wordLength = rand () % (6 - 3 + 1) + 3;
- }
- while(userPlayAgain != "no");
- // if (userPlayAgain != "no") {
- cout << "Your total score was: " << score;
- cout << "\n Thank you for playing! \n";
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment