In: Computer Science
I WANT THIS CODE TO BE SIMPLE BECAUSE I AM NEW TO CODING AND I WANT TO KNOW THE DETAILS! straight C
Write a quiz program that helps a student learn the multiplication operation. A series of questions are asked, such as: What is 12 mod 5?Note: the numbers 12 and 5 were randomly generated by your program. After the user types in their answer, print a suitable message to the screen. The game ends after 4 wrong answers.
quiz.c
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
// random seed
srand(time(0));
int a, b, answer,wrong=0;
// Ierate until 4 wrongly answered
while(wrong!=4)
{
// Generate a number from
[1,100]
a = rand()%100+1;
// Generate a number from
[1,10]
b = rand()%10+1;
// Printing to screen
printf("%d mod %d = ",a,b);
// Get answer from user
scanf("%d",&answer);
// If answer is correct
if(a%b==answer)
{
printf("Correct
answer\n");
}
// If answer is wrong
else
{
printf("Wrong
answer\n");
wrong++;
}
}
return 0;
}
output screenshot:
