Monday, September 6, 2010

Question Function part

#include <iostream>
#include <conio.h>
#include <time.h>
#include <string.h>
using namespace std;
const int size_question=4; //to make it really random, try to get around 70 questions
int i;

struct QUESTIONS
{
    string q;
    string ans;
    int status; //keep status of being given out yet or not. if already use, value 1
}questions[size_question];

void initializeQuestion (void);
void initializeStatus (void);

int main(void)
{
    srand(time(NULL));
    initializeQuestion ();
    label2:
    int randomQuestion=(rand()%size_question); //randomize the questions
    if (questions[randomQuestion].status==1)
       goto label2;
    string answer;
    cout<<"Question: "<<questions[randomQuestion].q<<endl;
    cout<<"Your answer: ";
    cin>>answer; //want to lower capitals answer 
    if (questions[randomQuestion].ans==answer)
    {    cout<<endl<<"That's correct!"<<endl; //return 1;
    }
    else
        cout<<endl<<"That's wrong..."<<endl;
    system("Pause");
    system("cls");
    goto label2;
}

void initializeQuestion (void)
{
    questions[0].q="1+2= ";
    questions[0].ans="3";
    questions[1].q="What is the name of the developer team that made this game?";
    questions[1].ans="mytho";
    questions[2].q="Some of memory access technique are random access, sequential access, direct access and _____ access.";
    questions[2].ans="associative";
    questions[3].q="4*120= ";
    questions[3].ans="480";   
       
    initializeStatus ();
}

void initializeStatus (void)
{
     for ( i=0; i<size_question; i++)
        questions[i].status=0;
}

No comments:

Post a Comment