#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char questions[][100] = {"1. what year did the c language debut?:",
"2. who is credited with crating c?:",
"3. what is the predecossor of c?:"};
char options[][100] = {"a. 1969","b. 1972","c. 1975","d. 1999",
"a. dennis r.","b. nikola tesla","c. john carmarck","d. doc b.",
"a. objective c","b. b","c. c++","d. c#"};
char answers[3] = {'b','a','b'};
int numberofquestions = sizeof(questions) / sizeof(questions[0]);
char space[] = " ";
char guess[numberofquestions];
char results[3][7];
int score = 0;
for(int i = 0; i < numberofquestions * 4; i++){
strncat(options[i], space, 25 - strlen(options[i]));
}
for(int i = 0; i < numberofquestions; i++){
printf("\n%s\n", questions[i]);
for(int j = 4 * i; j < 4 * (i + 1); j++){
printf("%s", options[j]);
}
printf("\n\nguess: ");
scanf("%c", &guess[i]);
scanf("%*c"); // this is for clearing \n from input buffer, * for ??
if(guess[i] == answers[i]){
score++;
}
}
for(int i = 0; i < numberofquestions; i++){
if(guess[i] == answers[i]){
strcpy(results[i], "correct");
}
else{
strcpy(results[i], "wrong");
}
}
printf("\n1st question is %s\n", results[0]);
printf("2nd question is %s\n", results[1]);
printf("3rd question is %s\n", results[2]);
printf("\ntotal score is %d/%d", score, numberofquestions);
return 0;
}
W hen I run the code with the correct answers 'b', 'a', and 'b' i get the output
1st question is correctcorrectcorrect
2nd question is correctcorrect
3rd question is correct
total score is 3/3
but if I run with the wrong answers I get the output
1st question is wrong
2nd question is wrong
3rd question is wrong
total score is 0/3
How can I fix this ?