Someone posted a question as to how a program could be written to ask questions, obtain an answer, and then compare it the user answer to the correct answer. I replied with a method of hard coding the questions and answers into an array, but thought about it in more detail. It might be useful to have an instructor be able to enter his or her questions and then the correct answer and store that info into a dat file. So I thought about that for awhile, but couldn't figure out exactly how to store the questions correctly... I got null pointer assignments. Anyway, I came up with something like
Any ideas as to how to approach this would be appreicated.
#define MAXNUM 4 // four questions & answers
#define MAXLEN 80 // max size of question string
int userAnswers[MAXNUM]; // assume an int value for now.
for(i = 0; i < MAXNUM; i++)
printf("Enter question %d: ", i);
// I debated over scanf or fgets but I'm not sure how
// to read in the string
printf("Enter the answer for question %d: ", i);
..... other code