#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
void main()
{
#define EASY_LEVEL 1
#define MEDIUM_LEVEL 2
#define HARD_LEVEL 3
#define QUIT 4
int Option;
bool Word_Complete = false;
bool Run = true;
#define NUMBEROFWORDSEASY 9
#define MAXWORDLENGTHEASY 6
int randomnumber;
char wordeasy[NUMBEROFWORDSEASY][MAXWORDLENGTHEASY] = { "print", "phone", "worth", "throw", "games", "study", "error", "debug", "build"};
char myChosenWordEasy[MAXWORDLENGTHEASY];
char input;
int length;
char scrambledword[MAXWORDLENGTHEASY];
char answer[MAXWORDLENGTHEASY];
int WordsAnswered;
int Guess;
int WordCount;
int i;
bool gotrandomchar = false;
do {
cout<< "Game intructions\n";
cout<< "Please select a difficulty level\n";
cout<< "1=Easy\n";
cout<< "2=Medium\n";
cout<< "3=Hard\n";
cout<< "4=Quit\n";
cin>> Option;
switch (Option)
{
case EASY_LEVEL:
do
{srand(time(NULL));
randomnumber = rand()%NUMBEROFWORDSEASY;
strcpy(myChosenWordEasy, wordeasy[randomnumber]);
cout << "The random word is " << myChosenWordEasy << endl;
bool flag[MAXWORDLENGTHEASY-1];
for (i=0;i<MAXWORDLENGTHEASY-1;i++)
flag[i] = false;
myChosenWordEasy[MAXWORDLENGTHEASY];
length = MAXWORDLENGTHEASY-1;
for (i=0;i<MAXWORDLENGTHEASY-1;i++) {
bool gotrandomchar = false;
do {
int rndpos = rand()%length;
if (flag[rndpos]==false) {
flag[rndpos] = true;
scrambledword[i] = myChosenWordEasy[rndpos];
gotrandomchar = true;
}
}
while (gotrandomchar==false);
}
scrambledword[MAXWORDLENGTHEASY-1] = NULL;
cout << "The original word is " << myChosenWordEasy << "\n";
cout << "The scrambled word is " << scrambledword << "\n";
cin >> answer;
if (answer == myChosenWordEasy) {
cout<< "The word is correct\n";
WordCount = WordsAnswered + 1;
if (WordsAnswered == 3) {
cout << "Well done!!!\n";
Word_Complete = true;
}
}
else {
cout<< "The word is not correct\n";
Guess = Guess + 1;
if (Guess == 3) {
cout<< "You have failed\n";
Word_Complete = true;
}
}
}
while(Word_Complete == false);
break;
case MEDIUM_LEVEL:
cout<< "Display scambled word Medium\n";
do {
cout<< "Medium loop is working\n";
Word_Complete = true;
}
while(Word_Complete == false);
break;
case HARD_LEVEL:
cout<< "Display scambled word Hard\n";
do {
cout<< "Hard loop is working\n";
Word_Complete = true;
}
while(Word_Complete == false);
break;
case QUIT:
Run = false;
default:
cout<< "Press enter to end game\n";
}
}
while (Run == true);
}
Bookmarks