Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Final Project.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <stdio.h>
- #include <time.h>
- using namespace std;
- char ToUpper(char c)
- {
- return(c >= 'a' && c <= 'z' ? 'A' + c - 'a' : c);
- }
- bool Contains(const char* str, const char c)
- {
- int i;
- while (str[i])
- {
- if (str[i] == c)
- return(true);
- i++;
- }
- return(false);
- }
- int main()
- {
- srand(time(0));
- char words[10][11] = { "ABC","BAD","CAT","DAD","EGG","FREE","GREAT",
- "HAPPY","ISLAND","JACK" };
- int wordToUse = rand() % 10;
- cout << words[wordToUse];
- char userEntered[26];
- for (int i = 0; i < 26; i++)
- userEntered[i] = 0;
- char c;
- int chances = 10;
- do
- {
- if (chances == 5)
- {
- int i = 0;
- int missingLetters = 0;
- char userMissed[26];
- for (int i = 0; i < 26; i++)
- userMissed[i] = 0;
- while (words[wordToUse][i])
- {
- char letterInWord = words[wordToUse][i];
- if (userEntered[letterInWord - 'A'] != 1)
- userMissed[letterInWord - 'A'] = 1;
- i++;
- }
- cout << Sum(userMissed, 26)
- }
- cout << "Enter a Letter" << endl;
- cin >> c;
- c = ToUpper(c);
- if (userEntered[c - 'A'] == 1)
- {
- cout << "You already picked this letter" << endl;
- continue;
- }
- else
- userEntered[c - 'A'] = 1;
- if (Contains(words[wordToUse], c))
- {
- cout << "You have found a match" << endl;
- // test to see if they have won
- bool didWin = true;
- int i = 0;
- while (words[wordToUse][i])
- {
- char letterInWord = words[wordToUse][i];
- if (userEntered[letterInWord - 'A'] != 1)
- didWin = false;
- i++;
- }
- if (didWin == true)
- {
- cout << "You Won!! Winning word was " << words[wordToUse]
- << endl;
- return(0);
- }
- continue;
- }
- chances--;
- } while (chances > 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement