Maths quiz game.c

 #include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<time.h>

#include<graphics.h>

void gameover(){


  system("cls");

   int gdriver = DETECT,gmode;

   initgraph(&gdriver,&gmode,"c:\\TC\\BGI");


  setbkcolor(BLACK);

  setcolor(GREEN);

  settextstyle(1,HORIZ_DIR,10);


  outtextxy(100,100,"game");

  outtextxy(200,200,"over");

  getch();


   closegraph();


}

void introduction()

{

  system("cls");

   int gdriver = DETECT,gmode;

   initgraph(&gdriver,&gmode,"c:\\TC\\BGI");


  setbkcolor(GREEN);

  setcolor(YELLOW);

  settextstyle(1,HORIZ_DIR,7);


  outtextxy(100,100,"programmed by ");

  outtextxy(200,200," sunil");

  getch();


   closegraph();

}

void start(){

  int gdriver= DETECT,gmode;

  initgraph(&gdriver,&gmode,"c:\\TC\\BGI");

  setbkcolor(BLUE);

  setcolor(YELLOW);

 // int x = getmaxx()/2;

 // int y = getmaxy()/2;

  settextstyle(1,HORIZ_DIR,7);


  outtextxy(100,10,"welcome to ");

  outtextxy(100,100,"quiz game");

  outtextxy(100,200,"To strat press");

  outtextxy(100,300,"any key");

  getch();

  closegraph();


}

int gameend=1,score = 0,correct=0;

int main(){

start();

introduction();

  srand(time(0));

  while(gameend!=0){

  int a,b,sum,input;

  system ("cls");

  a= rand()%100;

  b= rand()%100;

  sum=a+b;

  printf("enter the the sum of %d + %d : ",a,b);

  scanf("%d",&input);

  if(sum == input)

  {

    printf("you enterd correct answer");

    score+=5;

    correct++;

    getch();

  }

  else{

   printf("you entered wrong answer\n");

   gameend = 0;

   printf("your score is %d\n",score);

   printf("you answered %d  questions\n",correct);

  }

  }

  getch();

  gameover();

  return 0;

}

Comments

Popular posts from this blog

Snake game.c

Type declaration

Array with function