I am working on a simple C program to make a multiple choice quiz to help my students prepare for their exams. I used struct function. So far the program works fine
My question: 1)Is there a way to use my current code below to generate questions randomly?
2) How would you suggest keeping track of percentage answered correctly? (counter + for loop? while loop?
3) Is there anything I have done extremely inefficiently, can you recommend a solution? I'm genuinely a beginner so please not to complicated explanation. Thank you
Here's the code:
#include <stdio.h>
struct question
{
char quiz[130]; // Question will be stored here
char answer1[20]; // Text for multiple choice possible answer 1
char answer2[20]; // Text for multiple choice possible answer 2 ..
char answer3[20];
char answer4[20];
int correctAnswer;
};
int main (){
struct question one={
"Que significa la palabra 'ser'\n",
"1. to do",
"2. to be",
"3. to make",
"4. to understand",
2,
};
printf ("%s %s %s %s %s\n",one.quiz,one.answer1,one.answer2,one.answer3,one.answer4);
scanf ("%d",&one.correctAnswer);
if (one.correctAnswer!=2){
printf("Equivocado! 'ser' significa: to be\n");
}
else {
printf ("Correcto\n");
}
struct question two={
"Que significa la palabra 'poder'\n",
"1. to do",
"2. to read",
"3. to make",
"4. to be able to",
4,
};
printf ("%s %s %s %s %s\n",two.quiz,two.answer1,two.answer2,two.answer3,two.answer4);
scanf ("%d",&two.correctAnswer);
if (two.correctAnswer!=4){
printf("Equivocado! 'ser' significa: to be able to\n");
}
else {
printf ("Correcto\n");
}
Aucun commentaire:
Enregistrer un commentaire