• We hope you have a fantastic holiday season to close out 2025! Thank you all so much for being part of the Tom's Guide community!

please help sort this program

Status
Not open for further replies.

Nikithab

Commendable
Sep 29, 2016
1
0
1,510
#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
struct question{
int no;
char q[50],a[40];
char qoption[4][20];
char roption[20];
char pass[5];
};
void main()
{
FILE *fp,*ft;
int choice,choice2=1,choice3=1,r;
int count=0;
struct question
{
struct ques q[10];
char pass[5]='abcd';
char another;
char long int recsize;
};
printf("\t\t\t\t QUIZ\n \t\t\t\t1:Admin\n \t\t\t\t2:Student\n");
printf("please enter your choice");
scanf("%d",choice);
if(choice=1)
{
switch(choice)
{
case 1:
printf("Please enter yor password\n");
scanf("%s",choice);
p=(strcmp(choice,pass)==0)
if(p==0)
{
printf("\nCorrect password");
else
printf("\nInvalid password\n Enter the correct password");
p=(strcmp(choice,pass)==0)
if(p==0)
printf("\n correct password");
else if
printf("\n You have been blocked");
}
recsize=size of(q);
while(1)
{
system("cls");
printf("Welcome to Admin\n 1:Add Question\n 2:Modify question\n3: List the question\n4: Delete the question");
printf("0,exit");
printf("Your choice");
fflush(stdin);
choice2=getche();
switch(choice2)
{

case '1': fseek(fp,0,SEEK_END);
another=='Y';
while(another=='Y')
{
printf("\nEnter the question");
scanf("%s",q.question);
fwrite(&q,recsize,1,fp);
printf("\n Add another question(y/n)");
fflush(stdin);
another=getche();
}
break;
case '2':another='y';
while(another=='y')
{
printf("Enter the question to modify");
scanf("%s",ques question);
rewind (fp);
while(fread(&q,recsize,1,fp)==1)
{
if(strcmp(q.question,ques question)==0)
{
printf("\n Enter new question");
scanf("%s",q.ques);
fseek(fp,-recsize,SEEK_CUR);
fwrite(&q,recsize,1,fp);
break;
}
}
printf("\nmodify another question(y/n)");
fflush(stdin);
another=getche();
}
break;
case '3': rewind(fp);
while(fread(&q,recsize,1,fp)==1)
printf("\n%s",q.question);
getch();
}
break;
case '4': another='Y';
while(another=='Y')
{
printf("\nEnter the question to delete");
scanf("%s",q.question);
ft=fopen("TEMP.DAT","wb");
rewind(fp);
while(fread(&q,recsize,1,fp)==1)
if(strcmp(q.question,ques.question)!=0)
fwrite(&q,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("QUES.DAT");
remane("TEMP.DAT","QUES.DAT");
fp=fopen("QUES.DAT","rb+");
printf("Delete another question(y/n)");
fflush(stdin);
another=getche();
}
case '0': fclose(fp);
exit(0);

}
}
else
printf("Lets start the game")



switch(r)
{
case 1:
printf("\n\nWhat is our national bird");
printf("\n\nA.parrot\tB.crow\n\nC.peacock\tD.sparrow\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.peacock");
break;}

case 2:
printf("\n\n\nHow many letters in English alphabets");
printf("time period is same?");
printf("\n\nA.26\tB.24\n\nC.30\tD.21\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
printf("\n\nWrong!!! The correct answer is A.26");
break;

case 3:
printf("\n\n\nWhich is the heavier metal of these two? Gold or Silver? ");
printf("\n\nA.both equal\tB.silver\n\nC.none \tD.gold\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.gold");
break;}


case 4:
printf("\n\n\nWhich is the fastest animal on the land?");
printf("\n\nA.cheetah\tB.tiger\n\nC.lion\tD.gorilla\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.cheetah");
break;}


case 5:
printf("\n\n\nWhich is the largest animal in the world ?");
printf("\n\nA.blue whale\tB.godzilla\n\nC.dinosaur\tD.elephant\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.blue whale");
break;}

case 6:
printf("\n\n\nWhich is the largest country (area) in the world ?");
printf("\n\nA.India\tB.Russia\n\nC.USA\tD.Australia\n\n");
countq++;
if (toupper(getch())=='B' )
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is B.Russia");
break;}


case 7:
printf("\n\n\n Which is the tallest animal on the earth ?");
printf("\n\nA.zebra\tB.kangaroo\n\nC.giraffe\tD.Elephant\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.giraffe");
break;}


case 8:
printf("\n\n\nWhich is the hottest planet?");
printf("\n\nA.Earth\tB.Saturn\n\nC.Jupiter\tD.Venus\n\n");
countq++;
if (toupper(getch())=='D')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is D.Venus");
break;}


case 9:
printf("\n\n\nWhat is the capital of India ?");
printf("\n\nA.New Delhi\tB.Andra\n\nC.Karnataka\t\tD.Punjab\n\n");
countq++;
if (toupper(getch())=='A')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is A.New Delhi ");
break;}


case 10:
printf("\n\n\nWhich is the National Sport of India?");
printf("\n\nA.Cricket\tB.Kabadi\n\nC.Hockey\tD.Tennis\n\n");
countq++;
if (toupper(getch())=='C')
{printf("\n\nCorrect!!!");countr++; break;}
else
{printf("\n\nWrong!!! The correct answer is C.Hockey");
break;}


}
}


can you please tell me whats wrong in this program
 
Status
Not open for further replies.