Friday, 2 May 2014

Quiz Game in C

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void valid()
{
printf("\n \n Correct Answer\n");
}
void invalid()
{
printf("\n \n Wrong Answer\n");
}
void wel()
{
printf("\n\n \t\t\tWelcome to the C quiz \n");
}
void note()
{
printf("\n\n\nBASIC RULES OF GAME:-");
printf("\n\n\n\t --> The quiz has 5 very basic questions of the C Programming Language.\n");
printf("\t --> Programe can accept only  digits not a character.\n");
printf("\t --> You get '+3' point for every correct answer and '-1' for every\n \t     incorrect answer.\n");
printf("\t --> you have to choose only one option from '1,2,3,4'. \n");
printf("\n\n\n\n\n");
}
void main()
{

int score=0;
int answer;
char array[10];
int x=400, y =400;
clrscr();
wel();
printf("\n\n \t\t\tEnter your name: ");
gets(array);
note();
printf("\t \t Q1) Why is it called 'C'& not 'D' ?\n");
printf("\n\n \t \t[1]C stands for code\n\n \t \t[2]The inventors name started with a C\n\n \t \t[3]It developed after a language called 'B'\n\n \t \t[4]Why should I care?\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
 {
  if(answer==3)
  {
  valid();
  score=score+3;
  }
 else
 {
 invalid();
 score=score-1;
 }
}
else
 {
 printf( "invalid\n" );
 }
delay(2000);
clrscr();
wel();
note();
printf("\n\n \t \tQ2) It was developed at?\n");
printf("\n \t \t [1]IBMt\n\n \t \t [2]Bell Labsn\n\n \t \t [3]MITt\n\n \t \t [4]Microsoft(?)\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==2)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ3) Which of these is not a C keyword as per ANSI C ?\n");
printf("\n \t \t [1]externt\n\n \t \t [2]volatilen\n\n \t \t [3]entert\n\n \t \t [4]break\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==3)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ4) What is ANSI, btw? ?\n");
printf("\n \t \t [1]Area of Natural and Scientific Interest\n\n \t \t [2]American National Standards Institute\n\n \t \t [3]American National Standardization Institute\n\n \t \t [4]American National Society Of Intellectuals\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==2)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();
note();

printf("\n\n \t \tQ5)Which of these concepts is NOT supported by C ?\n");
printf("\n \t \t [1]Pointers\n\n \t \t [2]Functions\n\n \t \t [3]Strings\n\n \t \t [4]Namespaces\n");
scanf("%d", &answer);
if(answer==1||answer==2||answer==3||answer==4)
{
if(answer==4)
{
valid();
score=score+3;
}
else
{
invalid();
score=score-1;
}
}
else
{
printf( "invalid\n" );
}
delay(2000);
clrscr();
wel();

textcolor ( 1 );
cprintf("\n\n\n\n\n\n\n\n              Thank You for taking the Quiz.");
puts(array);
printf("\n\n\n\n\t \t \tTotal Score is:- %d out of 15", score);
getch();
}

No comments:

Post a Comment