1
我想寫一個關於arduino的5個問題測驗,它有三個可能的答案,並在最後輸出一個分數。我試圖在提出第一個問題的地方寫下它,然後在有人輸入他們的答案後,進入下一個問題。我在「。」之前遇到初始化程序有問題。令牌錯誤消息。你可以幫我嗎?如何在arduino上寫測驗
`typedef struct{
char question[];
char answer1[];
char answer2[];
char answer3[];
char correct_answer;
}question_t;
question_t questions[] = {questions[0], questions[1], questions[2], questions[3], questions[4]};
question_t questions[0].question = "1. What is the capital of Illinois?";
question_t questions[0].answer1 = "a) Chicago";
question_t questions[0].answer2 = "b) Springfield";
question_t questions[0].answer3 = "c) Carbondale";
question_t questions[0].correct_answer = 'b';
question_t questions[1].question = "2. Who is the governor of Wisconsin?";
question_t questions[1].answer1 = "a) Scott Walker";
question_t questions[1].answer2 = "b) Clay Matthews";
question_t questions[1].answer3 = "c) Cole Nebel";
question_t questions[1].correct_answer = 'a';
question_t questions[2].question = "3. Where is MSOE?";
question_t questions[2].answer1 = "a) Memphis";
question_t questions[2].answer2 = "b) Manitowoc";
question_t questions[2].answer3 = "c) Milwaukee";
question_t questions[2].correct_answer = 'c';
question_t questions[3].question = "4. Why is Justin Bieber in jail?";
question_t questions[3].answer1 = "a) DUI";
question_t questions[3].answer2 = "b) bad music";
question_t questions[3].answer3 = "c) looking like Miley Cyrus";
question_t questions[3].correct_answer = 'a';
question_t questions[4].question = "5. Who is Jim Jefferies?";
question_t questions[4].answer1 = "a) actor";
question_t questions[4].answer2 = "b) singer";
question_t questions[4].answer3 = "c) comedian";
question_t questions[4].correct_answer = 'c';
int score;
int i;
char c;
char read_user_input(char c);
void output_question(uint8_t i);
void output_score(void);
loop()
{
init();
score=0:
uint8_t i;
i=0;
while(i<5)
{
output_question(i);
c=read_user_input();
if(c==questions[i].correct_answer)
{
score=score+20;
}i++;
}
Serial.print(output_score());
}
void init(void)
{
questions[5]:
}`