I am making a hangman game, I created a randf to select from a batch of words, aswell as masked the words in order for the guesser to guess the letter of the random word. The issue lies in that I have no idea how to connect the two. I already made the loop but without actually connecting them it will always print when counter = 0 because I have not made the condition for when
for(int counter; answer != word; counter++;)
But then I get the error:
operand types are incompatible, ("char" and "char(*)[200]").
Any solutions?
#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");//will pause the rand function
//masking and unmasking word
char m = strlen(word[x]);//will count the number of letters of the random word
int mask[200]{};
for (int i = 0; i < m; ++i) //loop until all leters are masked
{
mask[i] = 0;
}
//Introduction
printf("Hey! Can you please save me? \n");
printf(" O\n/|\\ \n/ \\ \n");
//Ask for answer
printf("\nType a letter to guess the word and save me. The letter is case sensitive so please pick lower case or I might die\n");
char answer;
scanf_s("%d", &answer);
//loop w counter
for (int counter = 0; counter++;) {
if (counter == 0)
{
printf("\n");
}
else if (counter == 1)
{
printf("\n=========");
}
else if (counter == 2)
{
printf("\n+\n|\n|\n|\n|\n|\n=========");
}
else if (counter == 3)
{
printf("\n+---+\n| |\n|\n|\n|\n|\n=========");
}
else if (counter == 4)
{
printf("\n+---+\n| |\n| O\n|\n|\n|\n=========");
}
else if (counter == 5)
{
printf("\n+---+\n| |\n| O\n| |\n|\n|\n=========");
}
else if (counter == 6)
{
printf("\n+---+\n| |\n| O\n| |\n| / \\ \n|\n=========");
}
else if (counter == 7)
{
printf("\n+---+\n| |\n| O\n| /| \n| / \\ \n|\n=========");
}
else if (counter == 8)
{
printf("\n+---+\n| |\n| O\n| /|\\ \n| / \\ \n|\n=========");
}
else if (counter == 9)
{
printf("\nReally left me hanging there buddy");
return 0;
}
else
{
printf("\nThanks for saving me!");
}
return 0;
}
}
Aucun commentaire:
Enregistrer un commentaire