Quizzer

This is my quizzer so far. The problem is that I want a multiple choice answer system. ATM the quizzer converts the sting into a '3d' char array, if their is an underscore it will divert the copying onto a different part of the array.
This is how the string is stored after conversion:
{{{question}{answer}}{{question}{answer}}{{question}{answer}}}
Once this section has been phased the loop of questioning begins.

Should I make it a 4d array to allow a multiple choice answers?

Here is the code:

#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

char qa[100][100][100];
string response;
int questionNo;
int range;

//Leave a underscore after each question/answer
//add as many questions/answers as pos
string strqa = "Name?_alastair_Dad?_roger_Cat?_lilly_House Number?_24_Country?_england";

int main(void)
{
int currentletter=0;//this does changes
bool convert = 1;

int b = 0;

while (convert == true)
{

for(int i = 0;; i++,currentletter++)
{
if (strqa[currentletter] == '_')
{
currentletter++;
break;
}
qa[b][0][i] = strqa[currentletter];
}
for(int i = 0;; i++,currentletter++)
{
if (strqa[currentletter] == '_')
{
currentletter++;//this adds one to compensate for the space
break;//breaking never does bottom part of loop
}

qa[b][1][i] = strqa[currentletter];
if (strqa.size() -1 == currentletter)
{
convert = false;
goto breakloop;
}
}
range += 1;
b++;
}
breakloop:
range += 1;


while(1>0)
{
system ("cls");
//______________This is the random generator for the question

cout << "the range is from 0 to " << range -1 << endl;

srand ( time(NULL) );

questionNo = rand() % range + 0 ;

cout << "this is question " << questionNo << endl;
cout << qa[questionNo][0] << endl;

//____________________This is "if" true or false part

cin >> response;
if (response != qa[questionNo][1])
{
Beep (100,500);
cout << qa[questionNo][1] << " dir!?" << endl;
system ("pause");
}

else if (response == qa[questionNo][1])
{
cout << "TICK" << endl;
system ("pause");
}
}
}


Last edited on
Should I make it a 4d array to allow a multiple choice answers?
No. Use 1d array and provide usefull names for each. Why not
1
2
string question[100];
string answer[100];
for multiple answers you might have 2d array:
string multi_answer[100][100];

Generally it's a good idea to avoid more than 1 dimension
Please use code tags!
Topic archived. No new replies allowed.