Wednesday, February 10, 2010

MY NATIVE C PROJECT

#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
int a[30];
time_t seconds;
int m,s;
int q1()
{
clrscr();
gotoxy(0,0);
printf("time remaining=%d:%d min:sec",m,s);
printf("\n\nwhat is capital of india?\n1.kolkatta\n2.banglore\n3.delhi\n4.hyderabad\n5.no attempt\n");
printf("\nyour previous answer is %d",a[1]);
printf("\nenter your answer\t");
scanf("%d",&a[1]);
if(a[1]==1||a[1]==2||a[1]==3||a[1]==4||a[1]==5)
{
return(a[1]);
}
else
{
a[1]=5;
printf("invalid option entered\n");
delay(2000);
q1();
}
return 0;
}
int q2()
{
clrscr();
gotoxy(0,0);
printf("time remaining=%d:%d min:sec",m,s);
printf("\n\nwho is president of India?\n1.manmoham singh\n2.prathibha patil\n3.krishna prasad\n4.you\n5.no attempt\n");
printf("\nyour previous answer is %d",a[2]);
printf("\nenter your answer\t");
scanf("%d",&a[2]);
if(a[2]==1||a[2]==2||a[2]==3||a[2]==4||a[2]==5)
return(a[2]);
else
{
a[2]=5;
printf("invalid option entered\n");
delay(2000);
q2();
}
return 0;
}
int q3()
{
clrscr();
gotoxy(0,0);
printf("time remaining=%d:%d min:sec",m,s);
printf("\n\nwhat is the national animal?\n1.tiger\n2.peacock\n3.lion\n4.monkey\n5.no attempt\n");
printf("\nyour previous answer is %d",a[3]);
printf("\nenter your answer\t");
scanf("%d",&a[3]);
if(a[3]==1||a[3]==2||a[3]==3||a[3]==4||a[3]==5)
return(a[3]);
else
{
a[3]=5;
printf("invalid option entered\n");
delay(2000);
q3();
}
return 0;
}
int main()
{
int ch,code,wrg=0,crt=0,att=0,marks=0,n,i,z[5],x;
for(i=1;i<4;i++)
a[i]=5;
clrscr();
printf("\n\t\tTAKE MY TEST RULES AND REGULATIONS\n\n1.time period of the exam is 3 minutes\n2.each correct answer carries 3marks\n3.each wrong attempt carries -1mark\n\n\n\t\t\t hit enter to start the test ");
   getch();
   seconds = time (NULL);
   while (1)
  {

    if (time(NULL) - seconds <=180)
      {
       clrscr();
       m=(2-((time(NULL)-seconds)/60));
       n=(time(NULL)-seconds)/60;
       s=(60*(n+1)-(time(NULL)-seconds));
       printf("time remaining=%d:%d min:sec",m,s);
       printf("\n\nquestions attempted");
       for(i=1;i<4;i++)
       {
       if(a[i]==1||a[i]==2||a[i]==3||a[i]==4)
       printf("\t%d",i);
       }
       printf("\n\nquestions not attempted");
       for(i=1;i<4;i++)
       {
       if(a[i]==5)
       printf("\t%d",i);
       }
       printf("\n\nto logout enter 100\n");
       printf("\n\nenter question number\t");
       scanf("%d",&ch);
       switch(ch)
       {
       case 1:q1();
          break;
       case 2:q2();
          break;
       case 3:q3();
          break;
       case 100:goto l1;
       default:gotoxy(0,22);
           printf("invalid question number");
           delay(2000);
       }
      }
    else
    {
    goto l1;
    }
  }
l1:
clrscr();
printf("\n\nyou have succesfully logged out\n\n");
delay(3000);
x1:
x=1;
printf("enter secret code to know the result\t");
while(x<=4)
{
z[x]=getch();
printf("*");
x++;
}
if(z[1]=='c'&&z[2]=='s'&&z[3]=='e'&&z[4]=='0')
{
if(a[1]==3)
crt++;
else if(a[1]==1||a[1]==2||a[1]==4)
wrg++;
if(a[2]==2)
crt++;
else if(a[2]==1||a[2]==3||a[2]==4)
wrg++;
if(a[3]==1)
crt++;
else if(a[3]==3||a[3]==2||a[3]==4)
wrg++;
att=crt+wrg;
clrscr();
printf("no of questions attempted=%d",att);
printf("\nno of questions correct=%d",crt);
printf("\nno of questions wrong=%d",wrg);
marks=((crt*3)-(wrg*1));
printf("\nmarks obtained are %d",marks);
printf("\nhit enter to terminate window");
getch();
exit(1);
}
else
{
clrscr();
printf("wrong code entered\n\n try again\n");
delay(5000);
clrscr();
goto x1;
}
return(0);

}


FOLLOWERS