Shodan
06-14-2004, 06:15 PM
Im very new to programming in C++. I was wondering if there is a way to create a kind of Boolean Array that would relate to a character array, so in terms of a question and answer program, if the user was to get a question wrong a boolean flag would go up on that question number and so the person can go back to the question they got wrong.
Here is the program so far
#include<iostream.h>
#include<conio.h>
int Validate(void);
char YorN(void);
void main(void)
{
char Question [4][120] = {
{"\nQUESTION 1\n\n\n\t 123 - 39 = \n\n\t\t1\t64\n\n\t\t2\t44\n\n\t\t3\t74\n\n\t\t4\t84\n\n\n"},
{"\nQUESTION 2\n\n\n\t 123 + 39 = \n\n\t\t1\t162\n\n\t\t2\t166\n\n\t\t3\t62\n\n\t\t4\t66\n\n\n"},
{"\nQUESTION 3\n\n\n\t 123 * 9 = \n\n\t\t1\t1007\n\n\t\t2\t1107\n\n\t\t3\t1106\n\n\t\t4\t1116\n\n\n"}
};
char Answers[4] = {'4','1','2'};
char Answer[4];
bool Correct;
cout<<"\n\n Welcome to Total Objective Multi-Surveys (TOMS) prototype on-line test";
cout<<"\n\n\n\n\t\tPress ANY key to continue";
cin.get();
clrscr();
for(int loop=0;loop<3;loop++)
{
cout<<Question[loop];
cout<<"Please Enter Answer : ";
Answer[loop]=Validate();
if(Answer[loop]==Answers[loop])
{
Correct=true;
}
clrscr();
}
cout<<"Answer 1 "<<Answer[0]<<" Answer 2 "<<Answer[1]<<" Answer 3 "<<Answer[2];
cin.get();
}
int Validate(void)
{
bool valid=false;
char ch;
do{
ch=getch();
if ((ch>='1')&&(ch<='4'))
{
putchar(ch);
valid=true;
}
}while(valid==false);
return(ch);
}
The problem im having should be placed around line 30 as you can see where I put the "Correct=true" line.
Hope you can help me out, the only problem is I need to solve this in 3 days so the 18 June at the latest. I hope you can help because im stumped.
Many Thanks
James
Here is the program so far
#include<iostream.h>
#include<conio.h>
int Validate(void);
char YorN(void);
void main(void)
{
char Question [4][120] = {
{"\nQUESTION 1\n\n\n\t 123 - 39 = \n\n\t\t1\t64\n\n\t\t2\t44\n\n\t\t3\t74\n\n\t\t4\t84\n\n\n"},
{"\nQUESTION 2\n\n\n\t 123 + 39 = \n\n\t\t1\t162\n\n\t\t2\t166\n\n\t\t3\t62\n\n\t\t4\t66\n\n\n"},
{"\nQUESTION 3\n\n\n\t 123 * 9 = \n\n\t\t1\t1007\n\n\t\t2\t1107\n\n\t\t3\t1106\n\n\t\t4\t1116\n\n\n"}
};
char Answers[4] = {'4','1','2'};
char Answer[4];
bool Correct;
cout<<"\n\n Welcome to Total Objective Multi-Surveys (TOMS) prototype on-line test";
cout<<"\n\n\n\n\t\tPress ANY key to continue";
cin.get();
clrscr();
for(int loop=0;loop<3;loop++)
{
cout<<Question[loop];
cout<<"Please Enter Answer : ";
Answer[loop]=Validate();
if(Answer[loop]==Answers[loop])
{
Correct=true;
}
clrscr();
}
cout<<"Answer 1 "<<Answer[0]<<" Answer 2 "<<Answer[1]<<" Answer 3 "<<Answer[2];
cin.get();
}
int Validate(void)
{
bool valid=false;
char ch;
do{
ch=getch();
if ((ch>='1')&&(ch<='4'))
{
putchar(ch);
valid=true;
}
}while(valid==false);
return(ch);
}
The problem im having should be placed around line 30 as you can see where I put the "Correct=true" line.
Hope you can help me out, the only problem is I need to solve this in 3 days so the 18 June at the latest. I hope you can help because im stumped.
Many Thanks
James