Hi,
I'm trying to build a quiz machine for the kids. It will have an LCD for display and buttons for the multiple choice answers. I'm having trouble working with the datatypes. I'm converting from 'string constant' to "char*" as well as then trying to compare a int to a pointer.
I'd like to figure out how to do what I'm trying to do, then find out what the best way I probably should have tried, and then figure out how to move my multi-dimensional array in to PROGMEM and access that. Here is what I did:
#include <avr/pgmspace.h>
char* myQuiz [4] [6] = {
{"Third-grade students went to a concert in 8 buses. Each bus took 45 students. How many students went to the concert?", "320", "360", "380", "3240", "B"},
{"A company has 6 big trucks. Each truck has 18 wheels. How many wheels is this in all?", "24", "96", "108", "116", "C"},
{"On Friday, 1250 people visited the zoo. Three times as many people visited on Saturday than on Friday. How many people visited the zoo on Saturday?", "3615", "3650", "3750", "3753", "C"},
{"9000 - 3782", "5218", "5328", "6782", "12,782", "A"}
};
void doQuestion(byte questionNumber);
void getAnswer(byte questionNumber);
char response;
void setup() {
Serial.begin(9600);
DDRD = B00001110; // pins 4-7 are inputs for answer buttons.
PORTD = B11110000; // input pullups.
}
void doQuestion(byte questionNumber){
Serial.println(myQuiz[questionNumber][0]);
for (int i = 1; i < 5; i++ ) {
Serial.print(i);
Serial.print(".");
Serial.println(myQuiz[questionNumber][i]);
}
}
void getAnswer(byte questionNumber){
char* correctAnswer = myQuiz[questionNumber][5];
while(true){
switch(PIND){
case B01110011:
response = 'A';
break;
case B10110011:
response = 'B';
break;
case B11010011:
response = 'C';
break;
case B11100011:
response = 'D';
break;
}
if (correctAnswer == response){
Serial.println("correct");
} else {
Serial.println("incorrect");
}
}
}
void loop() {
doQuestion(0);
getAnswer(0);
}
So I have an array like {question. choice a, choice b, choice c, choice d, correct answer}. and then I want to show the question and the choices, then compare a button press with the last element of the array to see if the answer was correct.
Any advice is appreciated.
Thanks.