Answer to Question #201490 in C for Muhammad Usman

Question #201490

quiz about string



1
Expert's answer
2021-06-01T03:04:10-0400
#include <stdio.h>
#include <string.h>


struct Quiz{
	char question[50];
	char answers[4][50];
	int correctAnswer;
};


int main (){
	struct Quiz allQuiz[3];
	int userAnswer;
	int i,j;
	int numberCorrectAnswers=0;
	strcpy(allQuiz[0].question,"1. What character ends all strings?");
	strcpy(allQuiz[0].answers[0],"1. '.'");
	strcpy(allQuiz[0].answers[1],"2. ' '");
	strcpy(allQuiz[0].answers[2],"3. '\\0'");
	strcpy(allQuiz[0].answers[3],"4. \'\\n\'");
	allQuiz[0].correctAnswer=3;


	strcpy(allQuiz[1].question,"2. Which of the following functions compares two strings?");
	strcpy(allQuiz[1].answers[0],"1. compare();");
	strcpy(allQuiz[1].answers[1],"2. stringcompare();");
	strcpy(allQuiz[1].answers[2],"3. cmp();");
	strcpy(allQuiz[1].answers[3],"4. strcmp();");
	allQuiz[1].correctAnswer=4;


	strcpy(allQuiz[2].question,"3. Which of the following adds one string to the end of another?");
	strcpy(allQuiz[2].answers[0],"1. append();");
	strcpy(allQuiz[2].answers[1],"2. stringadd();");
	strcpy(allQuiz[2].answers[2],"3. strcat();");
	strcpy(allQuiz[2].answers[3],"4. stradd();");
	allQuiz[2].correctAnswer=3;


	for(i=0;i<3;i++){
		printf("%s\n",allQuiz[i].question);
		for(j=0;j<4;j++){
			printf("   %s\n",allQuiz[i].answers[j]);
		}
		printf("\nYour answer?: ");
		scanf("%d",&userAnswer);
		if(allQuiz[i].correctAnswer==userAnswer){
			numberCorrectAnswers++;
		}
		printf("\n");
	}
	printf("\nNumber of correct answers: %d\n\n",numberCorrectAnswers);
	


	getchar();
	getchar();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS