Sunday, January 29, 2012

Does anyone know how to make a 20 questions game in C coding? Help dont know where to start?

User interface to start a new game and quit the current game.

User interface to read the questions and select the answers.

Algorithms to generate questions, make guesses and decide when the game has ended.

Records and displays the number of questions asked and the time elapsed for each game.Does anyone know how to make a 20 questions game in C coding? Help dont know where to start?User interface can mean a lot of different things to different people.

The simplest of user interfaces is the command window (or DOS on Windows).

Here's an example of how to do this at the command prompt. You'll have to enhance it for your needs.



#include %26lt;stdio.h%26gt;

#include %26lt;stdlib.h%26gt;



int main()

{

char sChoice[50];

char sMenuChoices[] = {"New game", "Quit game"};

int iChoice = 0;

int maxStr = sizeof(s_choice)/sizeof(*s_choice);

int maxMenuChoices = sizeof(sMenuChoices)/sizeof(*sMenuChoice鈥?br>


printf("Choose from the following choices:\n");

for (int n = 0; n %26lt; maxMenuChoices; n++)

printf("\t%d) %s\n", n, sMenuChoices[n]);

printf("Enter choice: ");

fgets(sChoice, maxStr, stdin);

sscanf(s_choice, "%d", %26amp;iChoice);

switch(iChoice)

{

case 1:

newGame();

break;

case 2:

exit(0);

break;

}

return 0;

}



void newGame()

{

char answer[1024];

char questions[] = {"Why is the world round?", "Why is the earth green?", "What is the meaning of life?"};

char answers[] = {"Because it spins?", "Well, it's mostly blue.", "When you find out give me a call!"};

int maxQuestions = sizeof(questions)/sizeof(*questions);

int iQuestionToAsk;

srand(time()); /* Seed the random number generator with the current time */

iQuestion = rand() % maxQuestions;

printf("Question:\n%s\n", questions[iQuestion]

printf("\t%d) %s\n", n, questions[n]);

printf("Enter your answer below:\n");

fgets(answer, sizeof(answer)/sizeof(*answer), stdin);

if (strcmp(answer, answers[iQuestion]) == 0)

printf("You're a genious!\n");

else

printf("You're a bubble-headed moron.\n");

}

Does anyone know how to make a 20 questions game in C coding? Help dont know where to start?In don't know how to program it in C coding but i know how to in java, if you want to know i can write it down

No comments:

Post a Comment