#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <Windows.h>
#define SIZE 2
int Exercise();
int Tutorial();
int Competition ();
int main()
{
int diff;
char ans;
printf("\t\tAssalamualaikum and welcome to math game");
printf("\n");
printf("\n");
do
{
system("cls");
printf("Please choose category:");
printf("\n");
printf("1 for Exercise");
printf("\n");
printf("2 for Tutorial");
printf("\n");
printf("3 for Competition");
printf("\n");
printf("You choose number:");
scanf("%d",&diff);
printf("\n");
if(diff==1)
{
int e;
printf("Good Luck and All The Best");
printf("\n");
e=Exercise();
}
else if(diff==2)
{
int t;
t=Tutorial();
printf("\n");
}
else if(diff==3)
{
int c;
printf("Good Luck and All The Best");
printf("\n");
c=Competition();
}
else
{
printf("Invalid!!");
printf("\n");
printf("Program is terminated!!");
printf("\n");
printf("Please try again later!!");
printf("\n");
}
fflush(stdin);
printf("Do you want to continue ?(Y/N)\n");
scanf("%c",&ans);
}while(ans=='Y'||ans=='y');
system("pause");
return 0;
}
int Exercise()
{ int x,y,randno,randno1,k=45,m=23,n=60,o=9,p=11,correct=0,wrong=0;
char name[20];
srand(time(NULL));
randno=1+rand()%(100-1+1);
randno1=1+rand()%(100-1+1);
printf("Please enter your nickname:");
scanf("%s",&name);
printf("Hello %s \n", name);
printf("\n");
printf("1)\t%d+%d=",randno,randno1);
scanf("%d",&x);
y=randno+randno1;
printf("\n");
if (x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("2)\t%d-32=",randno1);
scanf("%d",&x);
y=randno1-32;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("3)\t%d/1=",randno1);
scanf("%d",&x);
y=randno1/1;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("4)\t%d+%d=",randno,k);
scanf("%d",&x);
y=randno+k;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("5)\t%d-%d=",m,o);
scanf("%d",&x);
y=m-o;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("6)\t%d*%d=",randno1,n);
scanf("%d",&x);
y=randno1*n;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("7)\t%d+%d=",p,randno);
scanf("%d",&x);
y=p+randno;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("8)\t%d*%d=",k,randno1);
scanf("%d",&x);
y=k*randno1;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("9)\t%d+74=",randno);
scanf("%d",&x);
y=randno+74;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("10)\t%d*2=",n);
scanf("%d",&x);
y=n*2;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("Total correct answer is %d",correct);
printf("\n");
printf("total wrong answer is %d",wrong);
printf("\n");
}
int Tutorial()
{
int randno,randno1,randno2,randno3,randno4,randno5,randno6,m=1,x,y;
char name[20];
srand(time(NULL));
randno=1+rand()%(100-1+1);
randno1=1+rand()%(100-1+1);
randno2=1+rand()%(100-1+1);
randno3=1+rand()%(100-1+1);
randno4=1+rand()%(100-1+1);
randno5=1+rand()%(100-1+1);
randno6=1+rand()%(100-1+1);
printf("Please enter your nickname:");
scanf("%s",&name);
printf("Hello %s \n", name);
printf("\n");
printf("1)\t%d+%d",randno,randno1);
y=randno+randno1;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d+%d=%d",randno,randno1,y);
printf("\n");
printf("2)\t%d+%d",randno3,randno);
y=randno3+randno;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d+%d=%d",randno3,randno,y);
printf("\n");
printf("3)\t%d-%d",randno4,randno1);
y=randno4-randno1;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d-%d=%d",randno4,randno1,y);
printf("\n");
printf("4)\t%d*%d",randno6,randno5);
y=randno6*randno5;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d*%d=%d",randno6,randno5,y);
printf("\n");
printf("5)\t%d-%d",randno4,randno2);
y=randno4-randno2;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d-%d=%d",randno4,randno2,y);
printf("\n");
printf("6)\t%d+%d",randno4,randno1);
y=randno4+randno1;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d+%d=%d",randno4,randno1,y);
printf("\n");
printf("7)\t%d/%d",randno4,m);
y=randno4/m;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d/%d=%d",randno4,m,y);
printf("\n");
printf("8)\t%d+%d",randno1,randno6);
y=randno1+randno6;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d+%d=%d",randno1,randno6,y);
printf("\n");
printf("9)\t%d*%d",randno5,randno3);
y=randno5*randno3;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d*%d=%d",randno5,randno3,y);
printf("\n");
printf("10)\t%d+%d",randno2,randno4);
y=randno2+randno4;
printf("\n");
printf("\tAnswer:");
printf("\n");
printf("\t%d+%d=%d",randno2,randno4,y);
printf("\n");
}
int Competition()
{
int x,y,i,randno,randno1,randno2,randno3,randno4,randno5,randno6,k=45,m=23,n=60,o=9,p=11,correct=0,wrong=0;
int total[SIZE];
char name[20];
srand(time(NULL));
randno=1+rand()%(100-1+1);
randno1=1+rand()%(100-1+1);
randno2=1+rand()%(100-1+1);
randno3=1+rand()%(100-1+1);
randno4=1+rand()%(100-1+1);
randno5=1+rand()%(100-1+1);
randno6=1+rand()%(100-1+1);
for(i=0;i<SIZE; i++)
{
printf("Please enter your name (player %d):",i+1);
scanf("%s",&name );
printf("1)\t%d+%d=",randno,randno1);
scanf("%d",&x);
y=randno+randno1;
printf("\n");
if (x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("2)\t%d-32=",randno1);
scanf("%d",&x);
y=randno1-32;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("3)\t%d/1=",randno1);
scanf("%d",&x);
y=randno1/1;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("4)\t%d+%d=",randno,k);
scanf("%d",&x);
y=randno+k;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("5)\t%d-%d=",m,o);
scanf("%d",&x);
y=m-o;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("6)\t%d*%d=",randno1,n);
scanf("%d",&x);
y=randno1*n;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("7)\t%d+%d=",p,randno);
scanf("%d",&x);
y=p+randno;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("8)\t%d*%d=",k,randno1);
scanf("%d",&x);
y=k*randno1;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("9)\t%d+74=",randno);
scanf("%d",&x);
y=randno+74;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
printf("10)\t%d*2=",n);
scanf("%d",&x);
y=n*2;
printf("\n");
if(x==y)
{
printf("correct!!");
correct=++correct;
}
else
{
printf("wrong!!");
wrong=++wrong;
}
printf("\n");
total[i]=correct;
correct=0;
printf("Total correct answer is %d",total[i]);
printf("\n");
printf("total wrong answer is %d",wrong);
wrong=0;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
}
printf("Total answer correct for player 1 is %d\n",total[0]);
printf("Total answer correct for player 2 is %d\n",total[1]);
if (total[0]>total[1])
{
printf("The winner is player 1");
printf("\n");
}
else if (total[1]>total[0])
{
printf("The winner is player 2");
printf("\n");
}
else if(total[0]==total[1])
{printf("Draw!!");
printf("\n\n");
}
}