Hello my friends,
The last couple of days im trying to design a quiz-like program that does the following:
The idea is to make a program that can make people practice Verbs. The user will receive an sentence, but the verb is a blank spot. This blank spot is the word that the user have to figure out. For example:
I couldn't believe she (make/made) .........a phone call during the lecture. The user has to fill in the blank spot by choosing 1 of the 3 given answers.
Now i want to do this by using the Struct. I have practices with different programs like making a small database where employees can fill in ther name, age, gender etc etc. But in this project im not sure how to begin.
I need a (struct sentence) with 2 datatypes, char question and char answer
The inputs will be 2 switches, on digital inputs. 1 switch is for the first answer, other for the other answer.
Hope someone can give me a hand with this! (a small starting program would be helpful :)!)
First of all you need either arrays of char (char[]) or pointers to char (char*) to hold more than one character.
Your struct holds one such element for the sentence, one for every answer, and the number of the right answer.
@OP
Check if the following codes are helpful to you! You can optimize the codes and make the program much more elegant.
//I couldn't believe she (make/made) ......... a phone call during the lecture.
struct
{
char *myArray1= "I couldn't believe she ";
char *myArray2 = "(make/made) ";
char *myArray3 = "......... ";
char *myArray4 = "a phone call during the lecture.";
} data;
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
Serial.print(data.myArray1); //I couldn't believe she
Serial.print(data.myArray2); //(make/made)
Serial.print(data.myArray2);
Serial.print(data.myArray3); //.......
Serial.println(data.myArray4); //a phone call during the lecture.
// data.myArray2 = "made";
// Serial.println(data.myArray2);
}
void loop()
{
if (digitalRead(2) == LOW) //made
{
Serial.print(data.myArray1);
data.myArray2 = "made ";
Serial.print(data.myArray2);
data.myArray3 = "";
Serial.print(data.myArray3);
Serial.print(data.myArray4);
}
if (digitalRead(3) == LOW)
{
//.....................................
}
delay(500);
}