write a Math application in C programming which has 5 steps : 1.allows user to i
ID: 3779360 • Letter: W
Question
write a Math application in C programming which has 5 steps :
1.allows user to input their first name and last name.
2. user can choose the level ( easy, medium, hard ) of + - x / ( pick one to do )
3. generate random operation and user have to fill in the answer ( put -1 or quit to exit )
4. program will count the total answers, % of right answers untile user put -1 or quit.
5. base on the % of right answers, program will pop up message such as :
100-90%: fantastic!!!
90-80%: excellent!!!
80-70%: not bad!!!
70%-50%: try harder!!!
50-0%: good luck next time!!!
Explanation / Answer
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
char firstname[30],lastname[30];
int choose_level,random_num;
int seedVal=0;
//t is a 'time_t' type variable
time_t t;
/* Intializes random number generator */
seedVal = (unsigned) time(&t);
srand(seedVal);
printf("1.Easy ");
printf("2.Medium ");
printf("3.Hard ");
printf("Choose level:");
scanf("%d",&choose_level);
switch(choose_level)
{
case 1:{
int i,num1,num2;
int ans,ans1;
int questions_count=0,score=0;
while(1)
{
//Generating random number
random_num=rand() % 4+1;
if(random_num==1)
{
num1=rand() % 9+1;
num2=rand() % 9+1;
ans1=num1+num2;
printf("%d + %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==2)
{
num1=rand() % 9+1;
num2=rand() % 9+1;
ans1=num1-num2;
printf("%d - %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==3)
{
num1=rand() % 9+1;
num2=rand() % 9+1;
ans1=num1*num2;
printf("%d * %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==4)
{
num1=rand() % 9+1;
num2=rand() % 9+1;
ans1=num1/num2;
printf("%d / %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
}
}
case 2:{
int i=0,num1=0,num2=0;
int ans=0,ans1=0;
int questions_count=0,score=0;
while(1)
{
//Generating random number
random_num=rand() % 4+1;
if(random_num==1)
{
num1=rand() % 99+10;
num2=rand() % 99+10;
ans1=num1+num2;
printf("%d + %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==2)
{
num1=rand() % 99+10;
num2=rand() % 99+10;
ans1=num1-num2;
printf("%d - %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==3)
{
num1=rand() % 99+10;
num2=rand() % 99+10;
ans1=num1*num2;
printf("%d * %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==4)
{
num1=rand() % 99+10;
num2=rand() % 99+10;
ans1=num1/num2;
printf("%d / %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
}
}
case 3:
{
int i=0,num1=0,num2=0;
int ans=0,ans1=0;
int questions_count=0,score=0;
while(1)
{
//Generating random number
random_num=rand() % 4+1;
if(random_num==1)
{
num1=rand() % 999+100;
num2=rand() % 999+100;
ans1=num1+num2;
printf("%d + %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==2)
{
num1=rand() % 999+100;
num2=rand() % 999+100;
ans1=num1-num2;
printf("%d - %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==3)
{
num1=rand() % 999+100;
num2=rand() % 999+100;
ans1=num1*num2;
printf("%d * %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
else if(random_num==4)
{
num1=rand() % 999+100;
num2=rand() % 999+100;
ans1=num1/num2;
printf("%d / %d = ?",num1,num2);
scanf("%d",&ans);
questions_count++;
if(ans==-1)
{
break;
}
if(ans1==ans)
{
printf("Correct! ");
score++;
}
else
printf("wrong! ");
}
}
}
}
printf("Total Questions %d:",questions_count);
printf("Correct Answers %d:",score);
double calPercent=((double)score/questions_count)*100;
if(calPercent>=90 && calPercent<=100)
printf(":: Fantastic ::");
else if(calPercent>=80 && calPercent<90)
printf(":: Excellent ::");
else if(calPercent>=70 && calPercent<80)
printf(":: Not Bad ::");
else if(calPercent>=50 && calPercent<70)
printf(":: Try Harder ::");
else if(calPercent>=0 && calPercent<50)
printf(":: Good Luck Next Time ::");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.