Tuesday 19 February 2013

Maths Game(using arithmatic operations)

Lets Enjoy this interested Maths Game...........!!!




And here is the source code of this interested Math game

#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#include <stdlib.h>
void head (void);
main()
{    
    char y='y';
    int n,scr=0,r;
    int a,b,c,ans,in;

    for(n=0;;)
    {
        head();  
A:    randomize();
    a=random(21);
    b=random(21);
    c=random(1000);
    gotoxy(15,15);
    printf("Score=%d",scr);
    if(a==0 || b==0)
    {
        goto A;
    }
    if(c<250)
    {
        gotoxy(36,10);
        printf("%02d+%02d=",a,b);
        ans=a+b;
    }
    else if (c>250 && c<500)
    {
        gotoxy(36,10);
        printf("%02d-%02d=",a,b);
        ans=a-b;
    }

 
    else if (c>500 && c<750)
    {
        gotoxy(36,10);
        printf("%02d*%02d=",a,b);
        ans=a*b;
    }
    else
    {
        r=a%b;
        if(a>b && r==0)
        {
        gotoxy(36,10);
        printf("%02d/%02d=",a,b);
        ans=a/b;
        }
        else{
            goto A;
        }
    }
//    sleep(2);
    scanf("%d",&in);
    if(in==ans)
    {/*printf("\a");
    printf("%d\n",ans);*/
    clrscr();
    scr++;
    }else {
        gotoxy(35,11);
        printf("\aWrong....!");
        scr=0;
        sleep(1);clrscr();
    }
    if(scr>50)
    {
        clrscr();
        head();
        gotoxy(20,11);
        printf("You played it well. Now pass this to your friend...");
        gotoxy(20,12);
        printf("Do you want to play again?(y/n))");
        y=getche();
        if (y!='y' || y!='Y')
        {
            exit(0);
        }
    }
    }
}


void head (void)
{
    int i;
    for(i=0;i<80;i++)
    {gotoxy(i+1,1);
    printf("-");
    gotoxy(i+1,24);
    printf("-");}
    gotoxy(24,2);
    printf("IS YOUR BRAIN IS WORKING PROPERLY?");
    gotoxy(27,3);
    printf("A Gift by:EHTISHAM UL HAQ\n");
    for(i=0;i<80;i++)
    printf("-");
//    printf("\n");
    gotoxy(1,25);
    printf("From:tutcfree.blogspot.com Or you can Follow me on ahmedehtisham@facebook.com");
}

No comments:

Post a Comment