mardi 30 décembre 2014

Why the randomize() function not working?

I and my friend are trying to make a "Hangman" game using C++ for our school project. But on compilation, the messages show that the standard functions randomize() and random were not declared in this scope. What is wrong in the code?



#include <iostream>
#include <cstdlib>
#include <cstring>
#include<cstdio>
using namespace std;
const int MAXLENGTH=80;
const int MAX_TRIES=5;
const int MAXROW=7;

int letterFill (char, char[], char[]);
void initUnknown (char[], char[]);

int main ()
{
char unknown [MAXLENGTH];
char letter;
int wrong_guesses=0;
char word[MAXLENGTH];
char words[][MAXLENGTH] =
{
"batman begins",
"superman returns",
"2012",
"tarzan",
"goal",
"300",
"space jam",
"transformers",
"megamind",
"spiderman"
};
randomize();
int n=random(10);
strcpy(word,words[n]);
initUnknown(word, unknown);

cout << "\n\nWelcome to hangman...Guess a Movie Name";
cout << "\n\nEach letter is represented by a star.";
cout << "\n\nYou have to type only one letter in one try";
cout << "\n\nYou have " << MAX_TRIES << " tries to try and guess the word.";
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

while (wrong_guesses < MAX_TRIES)
{
cout << "\n\n" << unknown;
cout << "\n\nGuess a letter: ";
cin >> letter;
if (letterFill(letter, word, unknown)==0)
{
cout << endl << "Whoops! That letter isn't in there!" << endl;
wrong_guesses++;
}
else
{
cout << endl << "You found a letter! Isn't that exciting!" << endl;
}

cout << "You have " << MAX_TRIES - wrong_guesses;
cout << " guesses left." << endl;
if (strcmp(word, unknown) == 0)
{
cout << word << endl;
cout << "Yeah! You got it!";
break;
}

}
if(wrong_guesses == MAX_TRIES)
{
cout << "\nSorry, you lose...you've been hanged." << endl;
cout << "The word was : " << word << endl;
}
cin.get();
return 0;
}
int letterFill (char guess, char secretword[], char guessword[])
{
int i;
int matches=0;
for (i = 0; secretword[i]!='\0'; i++)
{
if (guess == guessword[i])
return 0;
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}
void initUnknown (char word[], char unknown[])
{
int i;
int length = strlen(word);
for (i = 0; i < length; i++)
unknown[i]='*';
unknown[i]='\0';
}




Aucun commentaire:

Enregistrer un commentaire