How to randomize the questions on my Quiz Game?

Please help me on randomizing questions not numbers.

Page 1 of 1

4 Replies - 6120 Views - Last Post: 30 September 2009 - 08:33 AM Rate Topic: -----

#1 kaizer002   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-September 09

How to randomize the questions on my Quiz Game?

Posted 30 September 2009 - 07:15 AM

Hello guys, I'm a beginner programmer and as a matter of fact, me and my groupmates have made a game which is not yet finished and until now we are doing into it. We made only 3 questions because we will ask first some advice before encoding other questions. But we have a problem, we don't know how to randomize the questions. Here is the Source Code:

main()
{

char name[10];
int m;

	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */");
	gotoxy(27,4);printf("/* All rights reserved 2009 */");
	gotoxy(25,12);printf("Enter your name:");
	gets(name);
	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */");
	gotoxy(23,5);printf("Welcome %s to 'INTELLIGENCE MAXIMIZER!'\n\n\n",name);
	printf("Are you ready?!\n");
	printf("Press [1] to Continue...\n");
	printf("Press [2] to Exit...\n");
	printf("Enter Choice:");
	scanf("%d",&m);
	if(m==1)
	menu();
	else if(m==2)
	exit();
	}
	menu()
	{
	int x;
	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */\n");
	gotoxy(33,5);printf(">>>MAIN MENU<<<");
	gotoxy(20,11);printf("[1] START");
	gotoxy(20,13);printf("[2] DESCRIPTION");
	gotoxy(20,15);printf("[3] QUIT");
	gotoxy(20,20);printf("Enter choice:");
	scanf("%d",&x);
	if (x==1)
	start();
	else if(x==2)
	description();
	}

start()
{
	int s;
	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */");
	gotoxy(28,5);printf("WELCOME TO ELEMENTARY LEVEL!!\n");
	gotoxy(30,8);printf("[PRESS ENTER TO CONTINUE]\n\n");
	getch();
	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */");
	gotoxy(28,5);printf("WELCOME TO ELEMENTARY LEVEL!!\n");
	printf("\nAre you ready?\n");
	printf("[1] YES!!\n");
	printf("[2] Instructions \n");
	printf("[3] EXIT GAME\n");
	printf("Enter choice:");
	scanf("%d",&s);
		if(s==1)
		count();
		else if(s==2)
		instruction1();
		else if(s==3)
		exit();
	}

	count()
	{
	int x=5;
	do
	{
	sleep(1);
	clrscr();
	gotoxy(40,12);printf("%d",x);
	x=x-1;
	}
	while(x>=0);
	clrscr();
	elementary();
	}

	elementary()
	{
	int q1;
	clrscr();
	gotoxy(25,2);printf("/* INTELLIGENCE MAXIMIZER v0.1 */");
	gotoxy(32,3);printf("/* by Group Aztec */");
	printf("\n\nELEMENTARY LEVEL\n\n");
	printf("Animals with mammary glands are known as:\n");
	printf("[1] Mammals\n");
	printf("[2] Reptiles\n");
	printf("[3] Amphibians\n");
	printf("[4] None of the above\n");
	printf("Enter choice:");
	scanf("%d",&q1);
		if(q1==1)
		printf("Correct!\n[PRESS ENTER TO CONTINUE]\n\n");
		else if(q1==2 || q1==3 || q1==4)
		printf("Wrong!\n\n\n");
		else
		printf("DO NOT INPUT INVALID CHARACTERS!\n\nEnter choice:");
		getch();
	{
	int q2;
	printf("Which planet is known for having 63 or more natural satellites?\n");
	printf("[1] Uranus\n");
	printf("[2] Earth\n");
	printf("[3] Jupiter\n");
	printf("[4] Saturn\n");
	printf("Enter Choice:");
	scanf("%d",&q2);
		if(q2==3)
		printf("Correct!\n[PRESS ENTER TO CONTINUE]\n\n");
		else if(q2==1 || q2==2 || q2==4)
		printf("Wrong!\n\n\n");
		else
		printf("DO NOT INPUT INVALID CHARACTERS!\n\nEnter choice:");
		getch();

	{

	int q3;
	printf("Fertilization that takes place outside the body\n");
	printf("[1] Internal\n");
	printf("[2] External\n");
	printf("[3] Pollination\n");
	printf("[4] All of the above\n");
	printf("Enter choice:");
	scanf("%d",&q2);
		if(q2==2)
		printf("Correct!\n[PRESS ENTER TO CONTINUE]\n\n");
		else if(q2==1 || q2==3 || q2==4)
		printf("Wrong!");
		else
		printf("DO NOT INPUT INVALID CHARACTERS!\n\nEnter Choice:");

		}
		getch();
		}}
description()
{
	clrscr();
	printf("Game Description is Under Construction");
	getch();
	menu();
	}

instruction1()
{
	clrscr();
	printf("Level 1 Instructions are Under Construction");
	getch();
	menu();
	}



*I want to randomize the questions..
*When the user inputs an invalid character, what is the command to give him the ability to choose again the answer??
base on my code, I have no right to choose the answer again and the program itself will be terminated...

please help me...thanks..

Is This A Good Question/Topic? 0
  • +

Replies To: How to randomize the questions on my Quiz Game?

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: How to randomize the questions on my Quiz Game?

Posted 30 September 2009 - 07:47 AM

Search assignment 1: srand() and rand().
Search assignment 2: loops
Was This Post Helpful? 0
  • +
  • -

#3 olibenu   User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 538
  • Joined: 31-December 08

Re: How to randomize the questions on my Quiz Game?

Posted 30 September 2009 - 08:23 AM

this is what i use
int random(int low=0, int high=9)
{
	int value=0;
	do
	{
		value=rand()%100;
	}while (value<low || value>high);
	return value;
}


then use like this
int choice=random(1,3);
cout<<"you chose question "<<choice;


you need to
#include <cstdlib>

This post has been edited by olibenu: 30 September 2009 - 08:30 AM

Was This Post Helpful? 0
  • +
  • -

#4 AGRAC393   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Re: How to randomize the questions on my Quiz Game?

Posted 30 September 2009 - 08:28 AM

Yea, I would do it like they said. Just use random nubmers to determain it. KIS; Keep it simple
Was This Post Helpful? 0
  • +
  • -

#5 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 624
  • Joined: 24-July 08

Re: How to randomize the questions on my Quiz Game?

Posted 30 September 2009 - 08:33 AM

I see in your sub title, you want to randomize your questions, but you don't want to randomize numbers...The easiest way to do it is through numbers. If you have a multidemensional array, you can select your question by a number. Just create a number, then place it in the array to select your question.

But the harder part would be how to select the answers according to the question. The best advice i could give you is to use a "class" per each question. Then make a array of your classes, generate your number then select your question with that number.

Alot of people will give you code, but the logic behind your program is more important!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1