userxbw

word guess c++ (halfass working project of someone elses)

Apr 20th, 2023
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.35 KB | Gaming | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <iomanip>
  8.  
  9. using std::cout,std::cin,std::endl,std::string;
  10.  
  11. string PuzzleHint(string hint, string answer) {
  12.     hint = answer.at(0);
  13.     cout << "\n Hint: Starts with the letter " << hint << endl;
  14.     cout << "Your guess: ";
  15.     return hint;
  16. }
  17.  
  18. int GuessCorrectly(int score) {
  19.     score = score+1;
  20.     cout << "Congratulations! You got it correct. You got one point. \n ";
  21.     cout << "Would you like to play again?(yes/no): ";
  22.     return score;
  23. }
  24.  
  25. /*
  26.  
  27. string crossWord1() {
  28.    
  29. }
  30.  
  31. string crossWord2() {
  32.    
  33. }
  34.  
  35. string crossWord3() {
  36.    
  37. }
  38.  
  39. string crossWord4() {
  40.    
  41. }
  42. */
  43.  
  44. // this is not inside of loop so it is not being called to print again
  45.   // make it a function then call that function within the loop at the
  46.   // approate spot to print it again.
  47.   // to do:
  48.   // make it actually print "random" words
  49.   // needs a bank of real words ( words stored in an array would work)
  50.   // to be selected in a "random" form
  51.   // then "random" letters to be printed around the word in the matrix
  52.   // word to be randomly printed out forward, backward, and on a diangle
  53.   //pattern.
  54.  
  55.   void random_word() {
  56.   cout << "****************************Word Search Puzzle**************************** \n \n";
  57.  
  58.   cout << "A randomly generated puzzle is printed on the screen."
  59.   << " The\npuzzle has a word which varies in length. If the word is\nguessed correctly"
  60.   << " you will gain a point. \n\n\n";
  61.  
  62.   cout << "a b q g h u m e a y \n"
  63.   << "l j e v x a f i r c \n"
  64.   << "t v s e p g n b w k \n"
  65.   << "n d u f n f i t i j \n"
  66.   << "z v s r j o c w r a \n"
  67.   << "l i m e o y m c r t \n"
  68.   << "b r e n g q p e d j \n"
  69.   << "s a r p n g g u l p \n"
  70.   << "u j n q a n l k r y \n"
  71.   << "c u w a m h w l x e \n"
  72.   << "n d q k n r k f l q \n"
  73.   << "q t e g n a r o u q \n\n\n";
  74.  
  75.   cout << "****************************************************************************" << endl;
  76. }
  77. int ran_num(){
  78.     return (rand () % (6 - 3 + 1) + 3);
  79. }
  80.  
  81. int main () {
  82.   int wordLength;
  83.   int score;
  84.   string userGuess;
  85.   string userPlayAgain;
  86.   int threeLetterWord;
  87.   int fourLetterWord;
  88.   int fiveLetterWord;
  89.   int sixLetterWord;
  90.   string answer;
  91.   string hint;
  92.  
  93.  
  94.  
  95.   score = 0;
  96.   srand (time (0));
  97.    
  98.    do {
  99.       random_word();
  100.      
  101.      switch (ran_num()) { //wordLength
  102.      
  103.           case 3:
  104.           // debugging
  105.           cout<<"in 3\n";
  106.                 cout << "Find the 3 letter word. \n";
  107.                 threeLetterWord = rand() % 2 + 1;
  108.                 cout<<threeLetterWord<<endl;
  109.             //if (threeLetterWord == 2) {
  110.             switch ( threeLetterWord ) {
  111.                 case 2:
  112.                 answer = "bee";
  113.                 cout << "Your guess(type hint for a clue): ";
  114.                  
  115.                 //getline(cin, userGuess);
  116.                     cin>>userGuess;
  117.                     if (userGuess == "hint") {
  118.                         PuzzleHint(hint, answer);
  119.                         cin >> userGuess;
  120.                     }
  121.                     if (userGuess == "bee") {
  122.                         cout << endl;
  123.                         score = GuessCorrectly(score);
  124.                         cout << endl;
  125.                         cin >> userPlayAgain;
  126.                         cout << endl;
  127.                         // to stop it from skipping over cin
  128.                         std::cin.ignore(10, '\n');
  129.                     } else {
  130.                         cout << "\n That was incorrect.\n"
  131.                         << "Would you like to play again(yes/no): ";
  132.                         cin >> userPlayAgain;
  133.                         cout << endl;
  134.                         std::cin.ignore(10, '\n');
  135.                     }
  136.                 break;
  137.                 case 1:
  138.                     //if (threeLetterWord == 1) {
  139.                     answer = "ant";
  140.                     cout << "Your guess(type hint for a clue): ";
  141.                      
  142.                     getline(cin, userGuess);
  143.                     if (userGuess == "hint") {
  144.                         PuzzleHint(hint, answer);
  145.                         cin >> userGuess;
  146.                         std::cin.ignore(10, '\n');
  147.                     }
  148.                     if (userGuess == "ant") {
  149.                         cout << endl;
  150.                         score = GuessCorrectly(score);
  151.                          cin >> userPlayAgain;
  152.                          cout << endl;
  153.                          std::cin.ignore(10, '\n');  
  154.                          
  155.                     } else {
  156.                         cout << "\n That was incorrect.\n"
  157.                         << "Would you like to play again(yes/no): ";
  158.                         cin >> userPlayAgain;
  159.                         cout << endl;
  160.                         std::cin.ignore(10, '\n');
  161.                     }
  162.                     break;
  163.                     default:
  164.                     break;
  165.                 }
  166.       //}
  167.       break;
  168.       case 4:
  169.      // if (wordLength == 4) {
  170.         // debugging
  171.             cout<<"in 4\n";
  172.             cout << "Find the 4 letter word.\n";
  173.             fourLetterWord = rand() % 2 + 1;
  174.             //if (fourLetterWord == 2) {
  175.           switch (fourLetterWord) {
  176.               case 2:
  177.                 answer = "kiwi";
  178.                 cout << "Your guess(type hint for a clue): ";
  179.                  
  180.                 getline(cin, userGuess);
  181.                 if (userGuess == "hint") {
  182.                     PuzzleHint(hint, answer);
  183.                     cin >> userGuess;
  184.                     std::cin.ignore(10, '\n');
  185.                 }
  186.                 if (userGuess == "kiwi") {
  187.                     cout << endl;
  188.                     score = GuessCorrectly(score);
  189.                     cin >> userPlayAgain;
  190.                     cout << endl;
  191.                     std::cin.ignore(10, '\n');
  192.                 } else {
  193.                     cout << "\n That was incorrect.\n"
  194.                     << "Would you like to play again(yes/no): ";
  195.                     cin >> userPlayAgain;
  196.                     cout << endl;
  197.                     std::cin.ignore(10, '\n');
  198.                 }
  199.             break;
  200.            
  201.      // }
  202.       //if (fourLetterWord == 1) {
  203.             case 1:
  204.                 answer = "lime";
  205.                 cout << "Your guess(type hint for a clue): ";
  206.                  
  207.                 getline(cin, userGuess);
  208.             if (userGuess == "hint") {
  209.                 PuzzleHint(hint, answer);
  210.                 cin >> userGuess;
  211.                 std::cin.ignore(10, '\n');
  212.             }
  213.             if (userGuess == "lime") {
  214.                 cout << endl;
  215.                 score = GuessCorrectly(score);
  216.                 cin >> userPlayAgain;
  217.                 cout << endl;
  218.                 std::cin.ignore(10, '\n');
  219.             } else {
  220.                 cout << "\n That was incorrect.\n"
  221.                 << "Would you like to play again(yes/no): ";
  222.                 cin >> userPlayAgain;
  223.                 cout << endl;
  224.                 std::cin.ignore(10, '\n');
  225.             }
  226.             break;
  227.             default:
  228.             break;
  229.         }
  230.       //}
  231.       break;
  232.       case 5:
  233.        // debugging
  234.        cout<<"in 5\n";
  235.       //if (wordLength == 5) {
  236.         cout << "Find the 5 letter word.\n";
  237.         fiveLetterWord = rand() % 2 + 1;
  238.         //does not always give you a 2
  239.         //so now you're getting wrong
  240.         //answer even when no anwser
  241.         //has been given
  242.         //debugging
  243.         cout<<fiveLetterWord<<endl;
  244.      
  245.      // if (fiveLetterWord == 2) {
  246.             switch (fiveLetterWord) {
  247.                 case 2:
  248.                     answer = "lemon";
  249.                     cout << "Your guess(type hint for a clue): ";
  250.                      
  251.                     getline(cin, userGuess);
  252.                 if (userGuess == "hint") {
  253.                     PuzzleHint(hint, answer);
  254.                     cin >> userGuess;
  255.                     std::cin.ignore(10, '\n');
  256.                 }
  257.                 if (userGuess == "lemon") {
  258.                     cout << endl;
  259.                     score = GuessCorrectly(score);
  260.                     cin >> userPlayAgain;
  261.                     cout << endl;
  262.                     std::cin.ignore(10, '\n');
  263.                 } else {
  264.                     cout << "\n That was incorrect.\n"
  265.                     << "Would you like to play again(yes/no): ";
  266.                     cin >> userPlayAgain;
  267.                     cout << endl;
  268.                     std::cin.ignore(10, '\n');
  269.                 }
  270.       //}
  271.                 break;
  272.                
  273.       //if (fiveLetterWord == 1) {
  274.             case 1:
  275.                 answer = "mango";
  276.                 cout << "Your guess(type hint for a clue): ";
  277.                
  278.                 getline(cin, userGuess);
  279.             if (userGuess == "hint") {
  280.                 PuzzleHint(hint, answer);
  281.                 cin >> userGuess;
  282.                 std::cin.ignore(10, '\n');
  283.             }
  284.             if (userGuess == "mango") {
  285.                 cout << endl;
  286.                 score = GuessCorrectly(score);
  287.                 cin >> userPlayAgain;
  288.                 cout << endl;
  289.                 std::cin.ignore(10, '\n');
  290.             } else {
  291.                 cout << "\n That was incorrect.\n"
  292.                 << "Would you like to play again(yes/no): ";
  293.                 cin >> userPlayAgain;
  294.                 cout << endl;
  295.                 std::cin.ignore(10, '\n');
  296.             }
  297.             break;
  298.             default:
  299.             break;
  300.         }
  301.       //}
  302.       break;
  303.       case 6:
  304.        // debugging
  305.        cout<<"in 6\n";
  306.     // if (wordLength == 6) {
  307.     cout << "Find the 6 letter word.\n";
  308.     sixLetterWord = rand() % 2 + 1;
  309.       //if (sixLetterWord == 2) {
  310.         switch (sixLetterWord) {
  311.             case 2:
  312.                 answer = "orange";
  313.                 cout << "Your guess(type hint for a clue): ";
  314.                 getline(cin, userGuess);
  315.             if (userGuess == "hint") {
  316.                 PuzzleHint(hint, answer);
  317.                 cin >> userGuess;
  318.                 std::cin.ignore(10, '\n');
  319.             }
  320.             if (userGuess == "orange") {
  321.                 cout << endl;
  322.                 score = GuessCorrectly(score);
  323.                 cin >> userPlayAgain;
  324.                 cout << endl;
  325.                 std::cin.ignore(10, '\n');
  326.             } else {
  327.                 cout << "\n That was incorrect.\n"
  328.                 << "Would you like to play again(yes/no): ";
  329.                 cin >> userPlayAgain;
  330.                 cout << endl;
  331.                 std::cin.ignore(10, '\n');
  332.             }
  333.             break;
  334.       //}
  335.             case 1:
  336.             //if (sixLetterWord == 1) {
  337.                 answer = "banana";
  338.                 cout << "Your guess(type hint for a clue): ";
  339.                 getline(cin, userGuess);
  340.             if (userGuess == "hint") {
  341.                 PuzzleHint(hint, answer);
  342.                 cin >> userGuess;
  343.                 std::cin.ignore(10, '\n');
  344.             }
  345.             if (userGuess == "banana") {
  346.                 cout << endl;
  347.                 score = GuessCorrectly(score);
  348.                 cin >> userPlayAgain;
  349.                 cout << endl;
  350.                 std::cin.ignore(10, '\n');
  351.             } else {
  352.                 cout << "\n That was incorrect.\n"
  353.                 << "Would you like to play again(yes/no): ";
  354.                 cin >> userPlayAgain;
  355.                 cout << endl;
  356.                 std::cin.ignore(10, '\n');
  357.             }
  358.             break;
  359.             default:
  360.             break;
  361.         }
  362.       //}
  363.       break;
  364.       default:
  365.       break;
  366.   }
  367. //     }
  368.    //  wordLength = rand () % (6 - 3 + 1) + 3;
  369.  
  370.   } // end outer switch
  371.     while(userPlayAgain != "no");
  372.    // not needed if kick out of loop then game over
  373.    // just print results
  374.    
  375.  //   if (userPlayAgain != "no") {
  376.         cout << "Your total score was: " << score;
  377.         cout << "\n Thank you for playing! \n";
  378.     //}
  379.  
  380.   return 0;
  381. }
  382.  
Advertisement
Add Comment
Please, Sign In to add comment