I am doing a project for a small hangman game that picks from a random selection of words and the user has to guess what the word is with a scanf inputting letters with a counter that builds a hangman, resulting either in a game over or win.
The issue lies in that when using the word[x] it isn't accepting it as "Expression must have a constant value", this error comes up in;
int mask[m];
and
mask[i] = 0;
All I can guess is that the rand function is the issue, but I have no idea how to fix it, anyone has a clue?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <time.h>
#include <string>
#define ARRAY_SIZE 10
int main()
{
//randomwordgenerator
char word[ARRAY_SIZE][200] = { "tiger", "lion", "elephant", "zebra", "horse", "camel", "deer", "crocodile", "rabbit", "cat" };
int x = 0;
srand(time(0));
x = rand() % ARRAY_SIZE;
system("pause");
//masking and unmasking word
char m = strlen(word[x]);//will count the number of letters of the random word
int mask[m];
for (int i = 0; i < m; ++i) {
mask[i] = 0;
}
return 0;
}
//Still have to do the loop and counter that prints out hangman
Aucun commentaire:
Enregistrer un commentaire