0% found this document useful (0 votes)
9 views2 pages

#Include Iostream

This C++ program contains a word hunt game where the user tries to find hidden words in a 10x10 board. It stores 5 hidden words in an array, asks the user to guess a word, checks if it's correct, and keeps score. If the user guesses all words or chooses not to play again, the program ends.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

#Include Iostream

This C++ program contains a word hunt game where the user tries to find hidden words in a 10x10 board. It stores 5 hidden words in an array, asks the user to guess a word, checks if it's correct, and keeps score. If the user guesses all words or chooses not to play again, the program ends.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <string>
#include <cctype>
#include <set>
using namespace std;

void add() {
int close = 0;
system("color F");
cout << " \n WELCOME TO PROGRAMMING\n";
cout << " FIND THE HIDDEN WORDS IN THE WORD HUNT BOARD.\n\n";

cout << " H U J B F R I E N D\n";


cout << " E C O U T N T D K U\n";
cout << " A R R A Y T O M X H\n";
cout << " R R F I V U L D S M\n";
cout << " T D R N L P A R T U\n";
cout << " Z S A P Y T B M P S\n";
cout << " C I N U Y U Z J E I\n";
cout << " F L L T V O L H V C\n";
cout << " J B S A G B A T C K\n";
cout << " O P E N N E L A V S\n\n";

string words[] = {"COUT", "ARRAY", "INPUT", "OUTPUT", "CIN"};


const int totalWords = 5;
int score = 0;
set<string> guessedWords;

for (int i = 0; i < totalWords; ++i) {


string userGuess;
cout << "\t\n Enter the word that you see: ";
cin >> userGuess;

for (string::iterator it = userGuess.begin(); it != userGuess.end(); ++it)


{
*it = toupper(*it);
}

if (guessedWords.count(userGuess) > 0) {
cout << " THE WORD IS ALREADY ANSWERED. TRY A DIFFERENT WORD.\n";
continue;
}

bool correctGuess = false;


for (int j = 0; j < totalWords; ++j) {
if (userGuess == words[j]) {
cout << "\tYOU GUESSED THE WORD CORRECTLY! +1 pt \n";
++score;
guessedWords.insert(userGuess);
correctGuess = true;
break;
}
}

if (!correctGuess) {
cout << "\tSORRY, THE WORD IS INCORRECT. TRY A DIFFERENT WORD.\n";
}

if (i == 4) {
cout << "\n Congratulations, you've guessed " << score << " out of " <<
totalWords << " words correctly. Well done.\n";

char playAgain;
cout << "\n Do you want to play again? [Y/N]: ";
cin >> playAgain;
while (close != 1) {
if (playAgain == 'y' || playAgain == 'Y') {
close = 1;
system("cls");
add();
} else if (playAgain == 'n' || playAgain == 'N') {
close = 1;
} else {
cout << "Invalid entry!";
}
}
}
}
}

int main() {
add();
return 0;
}

You might also like