SHARE
TWEET

Untitled

a guest Dec 10th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Final Project.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <time.h>
  7. using namespace std;
  8. char ToUpper(char c)
  9. {
  10.     return(c >= 'a' && c <= 'z' ? 'A' + c - 'a' : c);
  11. }
  12. bool Contains(const char* str, const char c)
  13. {
  14.     int i;
  15.     while (str[i])
  16.     {
  17.         if (str[i] == c)
  18.             return(true);
  19.         i++;
  20.     }
  21.     return(false);
  22. }
  23. int main()
  24. {
  25.     srand(time(0));
  26.     char words[10][11] = { "ABC","BAD","CAT","DAD","EGG","FREE","GREAT",
  27.      "HAPPY","ISLAND","JACK" };
  28.     int wordToUse = rand() % 10;
  29.     cout << words[wordToUse];
  30.     char userEntered[26];
  31.     for (int i = 0; i < 26; i++)
  32.         userEntered[i] = 0;
  33.     char c;
  34.     int chances = 10;
  35.     do
  36.     {
  37.         if (chances == 5)
  38.         {
  39.             int i = 0;
  40.             int missingLetters = 0;
  41.             char userMissed[26];
  42.             for (int i = 0; i < 26; i++)
  43.                 userMissed[i] = 0;
  44.             while (words[wordToUse][i])
  45.             {
  46.                 char letterInWord = words[wordToUse][i];
  47.                 if (userEntered[letterInWord - 'A'] != 1)
  48.                     userMissed[letterInWord - 'A'] = 1;
  49.                 i++;
  50.             }
  51.             cout << Sum(userMissed, 26)
  52.         }
  53.         cout << "Enter a Letter" << endl;
  54.         cin >> c;
  55.         c = ToUpper(c);
  56.         if (userEntered[c - 'A'] == 1)
  57.         {
  58.             cout << "You already picked this letter" << endl;
  59.             continue;
  60.         }
  61.         else
  62.             userEntered[c - 'A'] = 1;
  63.         if (Contains(words[wordToUse], c))
  64.         {
  65.             cout << "You have found a match" << endl;
  66.             // test to see if they have won
  67.             bool didWin = true;
  68.             int i = 0;
  69.             while (words[wordToUse][i])
  70.             {
  71.                 char letterInWord = words[wordToUse][i];
  72.                 if (userEntered[letterInWord - 'A'] != 1)
  73.                     didWin = false;
  74.                 i++;
  75.             }
  76.             if (didWin == true)
  77.             {
  78.                 cout << "You Won!! Winning word was " << words[wordToUse]
  79.                     << endl;
  80.                 return(0);
  81.             }
  82.             continue;
  83.         }
  84.         chances--;
  85.     } while (chances > 0);
  86.  
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top