Program for Learning Tables

Hey guys,

I’m trying to make a program which young kids can train their Tables 1 till 10 with.
But since I’m not that experienced with arduino I have a little problem.
I need to make kinda like an array of arrays which need to remind how many times a question is answered good. If the question is 3x good, then it isn’t going to ask that question anymore.

(the program isn’t supposed to ask the questions 3x the same question, the wrong answered question comes back when the whole table is repeat.)

This is my code now:

#define nrOfTables 3
#define nrOfLines 3
int antwoord = 0;
int lineIndex = 0;
int tableIndex = 0;

void setup() {
Serial.begin(9600);
do {
for (int tableIndex = 0; tableIndex < nrOfTables; tableIndex++) {
for (int lineIndex = 0; lineIndex < nrOfLines; lineIndex++) {
Serial.print (lineIndex + 1);
Serial.print (" x “);
Serial.print (tableIndex + 1);
Serial.print (” = “);
while (Serial.available() == 0) {
}
Serial.println (”");
antwoord = Serial.parseInt ();
if (antwoord == (lineIndex + 1) * (tableIndex + 1)) {
Serial.println (“CORRECT”);
}
while (Serial.available() > 0) {
Serial.read ();
}
}
}
} while (antwoord != (lineIndex + 1) * (tableIndex + 1));
}

void loop() {
}

int lineIndex = 0;
int tableIndex = 0;

void setup() {
  Serial.begin(9600);
  do {
    for (int tableIndex = 0; tableIndex < nrOfTables; tableIndex++) {
      for (int lineIndex = 0; lineIndex < nrOfLines; lineIndex++) {

Why do you have local variables (the loop index variables) with the same name as global variables?

Just printing “CORRECT” is NOT sufficient. You need to somehow/somewhere record that the answer was correct (or wrong).

I’m completely missing the point of the do/while loop. The use of a do/while loop is almost, for beginners, the wrong structure to be using.

The code in a do...while is executed at least once. The code in a while... may not be executed at all which, strangely enough, is often the correct answer for beginners.

Hi,

To store the results, you can use a two dimentional array : byte answers[12][12]; When you generate your questions, you do need to look at that array to findout if it was already answered correctly 3 times :if (answers[a][b] == 3) //skip this question If the answer is correct, you do have to increase the number of good answers to that question. Furthermore, To make sure that you have gone thru all the questions, you have to keep tab of the number of questions that were answered correctly 3 times ( or the questions that you have left to ask)

answers[a][b]++;
if (answers[a][b] == 3) questionsLeft--;

You will need to to go thru the nested for an undefined number of times before all questions have been answered successfully.

while (questionsLeft > 0) {
  for (a, , )
    for (b, ,)
}

Jacques

It would also me much better to choose random values for the operands, in the range 1 to 10 (or 12 being the usual upper limit)l rather than running through the operands in order.