This is what i have so far and am now stuck!!
CODE
#include <iostream.h> // Required for cout, cin function
#include <string.h> // Required for any string operation functions
#include <time.h> // Required for time() function
#include <stdlib.h> // Required for srand() function
#include <stdio.h>
#include <cstdlib> // for system.("cls"), abs() and rand() functions
// ---------------------------------------------------------
//
int main() {
struct player {
int words_correct;
int number_of_guesses;
int number_of_lives;
int player_score;
};
//
player myPlayer;
//
myPlayer.words_correct = 0;
myPlayer.number_of_guesses = 0;
myPlayer.number_of_lives = 5;
myPlayer.player_score = 0;
//
bool keep_playing = true;
//
//
do {
//
//
//
system("cls");
cout << "================================================================\n\n";
cout << " WORD SCRAMBLE \n\n";
cout << "================================================================\n";
cout << "\n";
cout << "Welcome to the Word Scramble game!\n";
cout << "The goal of this game is to guess the word letter by letter, you\n";
cout << "will be given points for each word you get correct. You have \n";
cout << "five lives, you will lose a ife for each letter you guess \n";
cout << "incorrectly.\n";
cout << "\n";
cout << "================================================================\n";
cout << "\n";
cout << "Lives: " << myPlayer.number_of_lives << "\n";
cout << "Score: " << myPlayer.player_score << "\n";
cout << "\n";
cout << "================================================================\n";
//
{
#define NUMBEROFWORDS 20
#define MAXWORDLENGTH 20
char myWordList[NUMBEROFWORDS][MAXWORDLENGTH] = { "one", "two", "three",
"four", "five", "six",
"seven", "eight", "nine",
"ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen",
"nineteen", "twenty", };
{
char myChosenWord[MAXWORDLENGTH];
char guess;
cin >> guess;
srand(time(NULL)); /* initialize random number generator - without
this the random number generated will be the same
everytime the program runs */
do {
{
int randomnumber = rand()%NUMBEROFWORDS; // generate a random number (0 to NUMBEROFWORDS-1)
strcpy(myChosenWord, myWordList[randomnumber]); /* copy the content of myWordList[randomnumber]
to myChosenWord */
}
} while (keep_playing = true);
char currentword[NUMBEROFWORDS] = {myChosenWord};
bool flag[MAXWORDLENGTH-1];
for (int i=0;i<MAXWORDLENGTH-1;i++)
flag[i] = false;
char scrambledword[MAXWORDLENGTH];
int length = MAXWORDLENGTH;
for (i=0;i<MAXWORDLENGTH-1;i++) {
bool gotrandomchar = false;
do {
int rndpos = rand()%length;
if (flag[rndpos]==false) {
flag[rndpos] = true;
scrambledword[i] = currentword[rndpos];
gotrandomchar = true;
}
} while (gotrandomchar==false);
}
scrambledword[MAXWORDLENGTH-1] = NULL;
//cout << "The original word is " << testword << "\n";
cout << "The scrambled word is " << scrambledword << "\n";
//
//
while (keep_playing = true);
scrambledword[MAXWORDLENGTH-1] = NULL;
cout << "The scrambled word is " << scrambledword << "\n";
cout << "Guess the word letter by letter\n";
char inputdata;
cin >> inputdata;
if (inputdata=='i') {
//
//
cout << "Correct! Please continue.\n";
("player_score = player_score + 1");
} else {
//
//
cout << "Sorry, that is not the correct answer.\n";
("number_of_lives = number_of_lives -1");
}
}
//return 1;
}
}
If any one show me were i have gone wrong it would be great help as this has to be in today