I need to write a program in C using functions to help a child practice their ma
ID: 3711378 • Letter: I
Question
I need to write a program in C using functions to help a child practice their math facts. Addition, subtraction, multiplication and division can be used. The numbers need to be created using a random number generator using numbers 1-9. There needs to be a menu to allow the child to choose between the 4 operations listed above, with the 5th option being to quit. There needs to be positive feedback given to the child when he or she gets the problem right, and two chances to enter the correct answer if they get it wrong the first time, and the answer given if they get it wrong all three times. There needs to be 5 problems total. See sample menu below.
Menu
1. Addition
2. Subtraction
3. Multiplication
4. Integer Division
5. Quit
Thanks!
Explanation / Answer
//Program to generate random variables and perform calculations:
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int main()
{ srand((unsigned)time(NULL));//random numbers sre generated varying with time
int r,s,t,var;
r = (rand()%10)+1 ;
s = (rand()%10)+1 ;
printf("%d %d ", r,s);
printf("1.Addition 2.Subtraction 3.Multiplication 4.Integer division 5.Quit ");
printf("Enter the choice ");
scanf("%d ",&var);//depending on the variable the switch statement cases execute
switch(var)
{
case 1:
printf("Addition of two random numbers:");
t=r+s;
printf("%d",t);
break;
case 2:
printf("subtraction of two random numbers:");
t=r-s;
printf("%d",t);
break;
case 3:
printf("Multiplication of two random numbers:");
t=r*s;
printf("%d",t);
break;
case 5:
printf("division of two random numbers:");
t=r/s;
printf("%d",t);
break;
default:
printf("Exit of the program");
break;
}
return 0;
}