URGENT please help this code is not running properly i need to submit tommorow

Hi so i need to submit this code tomorrow as my school project but its not running properly this is a quiz maker with built in calculator code which can make 2 kinds of quizzes 1)a random quiz in which there can be any random question and 2) a topic wise quiz meaning the user can create topics such as former presidents and the user can write how many ever questions and answers he/she wants in it this code has 3 functions one function is inside of a class that is a calculator code and there are two other functions one is for writing questions and answers into a topic wise quiz and a random quiz and another to read and display them i can write the code both topic wise and the random one and i can also read the random quiz but when i select to read from the topic wise quiz nothing happens the code just stops working i am using turbo c++ 4.0 as my school requires me to use that but i have tried multiple other compilers such as gnu++ in code blocks and many online compilers but same problem occurs even in other compilers you can change the iostream.h and filestream.h to just iostream and fstream and type using namespace std before all the code to make this code run on modern compilers please help me get this fixed!!!
#include<iostream.h>
#include<math.h>
#include<stdio.h>
#include<fstream.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>

int ans;
char iyon[10];
char arg[10];
struct player
{char name[40];
int score;
char gamemode[20];
};
player play;
int noqp[50];
struct quiz_rand
{
char qn[50];
char op1[50];
char op2[50];
char op3[50];
char op4[50];
int correct;
};
quiz_rand wri;
quiz_rand wrar[50];

struct quiz_new
{
char name[20];
char qn[50];
char op1[50];
char op2[50];
char op3[50];
char op4[50];
int correct;
};
quiz_new writ;
quiz_new writ1;
quiz_new wg[5][10];

int noq;
char doing[10];
char yon[5];
int inderx;
ifstream fin;
ofstream fout;
int r;

class func
{public:
void calc()
{
cout<<endl;
cout<<"******************** Calculator ******************\n";
cout<<"---------------------------------------------------\n";
cout<<"Operations\t"<<"\tTrigonometric Functions"<<"\t\tLogarithmic Functions\n";
cout<<"------------------------------------------------\n";
cout<<"1: Division\t\t"<<"7: Sin\t\t"<<"\t\t13: Log"<<endl;
cout<<"2: Multiplication\t"<<"8: Cos\t\t"<<"\t\t14: Log with base 10"<<endl;
cout<<"3: Subtraction\t\t"<<"9: Tan\t\t"<<endl;
cout<<"4: Addition\t\t"<<"10: Inverse of Sin"<<endl;
cout<<"5: Exponent\t\t"<<"11: Inverse of Cos"<<endl;
cout<<"6: Square root\t\t"<<"12: Inverse of Tan"<<endl;
cout<<"Enter the function that you want to perform : ";
int c;
float a,b,PI;
cin>>c;

PI=3.14159265;

if(c==1)
{cout<<"Enter 1st number : ";
cin>>a;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<"Division = "<<a/b<<endl;}
else if(c==2)
{cout<<"Enter 1st number : ";
cin>>a;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<"Multiplication = "<<a*b<<endl; }
else if(c==3)
{cout<<"Enter 1st number : ";
cin>>a;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<"Subtraction = "<<a-b<<endl;
}
else if(c==4)
{cout<<"Enter 1st number : ";
cin>>a;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<"Addition = "<<a+b<<endl; }

else if(c==5)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Enter the exponent : ";
cin>>b;
cout<<"Exponent = "<<pow(a,b)<<endl;
}
else if(c==6)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Square Root = "<<sqrt(a)<<endl;
}
else if(c==7)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Sin = "<<sin(a)<<endl;
}
else if(c==8)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Cos = "<<cos(a)<<endl;
}
else if(c==9)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Tan = "<<tan(a)<<endl;
}
else if(c==10)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Inverse of Sin = "<<asin(a)*180.0/PI<<endl;
}
else if(c==11)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Inverse of Cos = "<<acos(a)*180.0/PI<<endl;
}
else if(c==12)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Inverse of tan = "<<atan(a)*180.0/PI<<endl;
}
else if(c==13)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Log = "<<log(a)<<endl;
}
else if(c==14)
{cout<<"Enter the number : ";
cin>>a;
cout<<"Log with base 10 = "<<log10(a)<<endl; }
else
cout<<"Wrong Input"<<endl;
}
};

func cal;

void quiz_write()
{
cout<<"do you want to write a question in the random quiz or make seperate quiz"<<endl<<"1-random quiz"<<endl<<"2-seperate quiz"<<endl;
cin>>r;
if(r==1)
{
fout.open("randomquiz.txt",ios::app);
cout<<"enter the question:";
gets(wri.qn);
cout<<"enter option-1:";
gets(wri.op1);
cout<<"enter option-2:";
gets(wri.op2);
cout<<"enter option-3:";
gets(wri.op3);
cout<<"enter option-4:";
gets(wri.op4);
cout<<"NOW SAY WHICH IS THE CORRECT OPTION 1 or 2 or 3 or 4:";
cin>>wri.correct;
cout<<"now adding your question";
fout.write((char*)&wri,sizeof(wri));
fout.close();
fin.open("indexr.txt");
fin>>inderx;
fin.close();
inderx=inderx+1;
fout.open("indexr.txt",ios::trunc);
fout<<inderx;
fout.close();
}
else if(r==2)
{
fout.open("quiz.txt",ios::app);
cout<<"enter how many question do you want to be in this quiz:";
cin>>noq;

if(noq==1)
{for(int i=0;i<noq;i++)
{
cout<<"enter the name of the quiz:";
gets(writ.name);
cout<<"enter the question:";
gets(writ.qn);
cout<<"enter the first option:";
gets(writ.op1);
cout<<"enter the second option:";
gets(writ.op2);
cout<<"enter the third option:";
gets(writ.op3);
cout<<"enter the fourth option:";
gets(writ.op4);
cout<<"now say which is the correct option:";
cin>>writ.correct;
fout.write((char*)&writ,sizeof(writ));
}
}
else if(noq>1)
{
cout<<"enter the name of the quiz:";
gets(writ.name);
cout<<"enter the question:";
gets(writ.qn);
cout<<"enter the first option:";
gets(writ.op1);
cout<<"enter the second option:";
gets(writ.op2);
cout<<"enter the third option:";
gets(writ.op3);
cout<<"enter the fourth option:";
gets(writ.op4);
cout<<"now say which is the correct option:";
cin>>writ.correct;
fout.write((char*)&writ,sizeof(writ));
int noq1=noq-1;
for(int i=0;i<noq1;i++)
{
cout<<"enter the question:";
gets(writ.qn);
cout<<"enter the first option:";
gets(writ.op1);
cout<<"enter the second option:";
gets(writ.op2);
cout<<"enter the third option:";
gets(writ.op3);
cout<<"enter the fourth option:";
gets(writ.op4);
cout<<"now say which is the correct option:";
cin>>writ1.correct;
fout.write((char*)&writ,sizeof(writ));
}
}
}

fout.close();

fout.open("indexn.txt",ios::app);
fout<<noq;
fout.close();
}
Last edited on
void quiz_read()
{cout<<endl<<"Hey There how are you today:";
gets(doing);
if(strcmp(doing,"great")==0)
{cout<<"that is great";
}
else
{
cout<<"that is sad";
}
cout<<endl<<"are you ready to play the quiz?:";
cin>>yon;
if(strcmp(yon,"yes")==0)
cout<<endl<<"great lets begin:";
else
{
cout<<endl<<"too bad we are going to play anyways";
}

cout<<endl<<"please say your name:";
gets(play.name);
cout<<"*nice name you got there"<<"\t";
puts(play.name);
cout<<"*just kidding i am a computer i have no idea if you have a nice name or not"<<endl<<"*anyways so where were we"<<endl<<"*aah right so choose from the options below as to what kind of quiz do you want to play"<<endl<<"1- a random quiz with questions you might have no idea of"<<endl<<"2-play a particular quiz from a list of various different quizes"<<endl;
cin>>ans;
if(ans==1)
{pos1:
strcpy(play.gamemode,"random quiz");
fin.open("indexr.txt");
fin>>inderx;
fin.close();

fin.open("randomquiz.txt");
for(int i=0;i<inderx;i++)
{
fin.read((char*)&wri,sizeof(wri));
strcpy(wrar[i].qn,wri.qn);
strcpy(wrar[i].op1,wri.op1);
strcpy(wrar[i].op2,wri.op2);
strcpy(wrar[i].op3,wri.op3);
strcpy(wrar[i].op4,wri.op4);
int ca=0;
ca=wri.correct;
wrar[i].correct=ca;
}
fin.close();
fin.open("indexr.txt");
int vel=0;
fin>>vel;
fin.close();
int hmq=0;
cout<<"how many questions do you want to play for:";
cin>>hmq;
play.score=0;
for(int jk=0;jk<hmq;jk++)
{
int ansr=0;
int rv=(rand()%inderx);
cout<<wrar[rv].qn;
cout<<endl<<"your options are:";
cout<<endl<<wrar[rv].op1;
cout<<endl<<wrar[rv].op2;
cout<<endl<<wrar[rv].op3;
cout<<endl<<wrar[rv].op4;

cout<<endl<<"do you need to use a calculator for this:";
gets(arg);
while(strcmp(arg,"yes")==0||strcmp(arg,"YES")==0)
{cal.calc();
cout<<"do you want to use the calculator again:";
gets(arg);
}

cout<<endl<<"what is the answer:";
cin>>ansr;
if(ansr==wrar[rv].correct)
{
cout<<"correct answer";
play.score=play.score+1;
}

else
{cout<<"wrong answer";
cout<<"the correct answer is:"<<wrar[rv].correct<<endl;
}
}
play.score=play.score/hmq*100;
fout.open("randomscore.txt",ios::app);
fout.write((char*)&play,sizeof(play));
fout.close();

cout<<endl<<"do you want to play the quiz again:";
gets(iyon);
if(strcmp(iyon,"yes")==0||strcmp(iyon,"YES")==0)
{
cout<<endl<<"which quiz do you want to play:"<<endl<<"1-random quiz"<<endl<<"2-topic wise quiz"<<endl;
int shar;
cin>>shar;
if(shar==1)
goto pos1;
else
goto pos2;
}


}
else if(ans==2)
{
pos2:
strcpy(play.gamemode,"topic wise");
int rd=0;
fin.open("indexn.txt");
while(!fin.eof())
{fin>>noqp[rd];
rd++;
}
fin.close();
fin.open("quiz.txt");
int par=0;
while(!fin.eof());
{
for(int lk=0;lk<noqp[par];lk++)
{fin.read((char*)&wg[par][lk],sizeof(wg[par][lk]));
}par++;
}
fin.close();
cout<<"These are the following quizes that are available:";
for(int jh=0;jh<rd;jh++)
{
cout<<endl<<jh+1<<"\t"<<wg[jh][0].name;
}
int din;
cout<<endl<<"which one do you want to play?";
cin>>din;
cout<<"ok great lets see how great you are at that subject"<<endl;
for(int rdf=0;rdf<noqp[din-1];rdf++)
{cout<<wg[din-1][rdf].name<<endl;
for(int idc=0;idc<strlen(wg[din-1][rdf].name);idc++)
{
cout<<"*";
}play.score=0;
cout<<endl<<wg[din-1][rdf].qn;
cout<<endl<<"your options are:";
cout<<endl<<wg[din-1][rdf].op1;
cout<<endl<<wg[din-1][rdf].op2;
cout<<endl<<wg[din-1][rdf].op3;
cout<<endl<<wg[din-1][rdf].op4;
cout<<endl<<"do you need to use a calculator for this:";
gets(arg);
while(strcmp(arg,"yes")==0||strcmp(arg,"YES")==0)
{cal.calc();
cout<<"do you want to use the calculator again:";
gets(arg);
}

cout<<endl<<"what is your answer:";
int nqa=0;
cin>>nqa;
if(nqa==wg[din-1][rdf].correct)
{
cout<<"correct answer";
play.score++;
}
else
{cout<<"wrong answer"<<endl<<"the correct answer is:"<<wg[din-1][rdf].correct<<endl;
}

}
play.score=play.score/noqp[din-1]*100;
fout.open("scores.txt");
fout.write((char*)&play,sizeof(play));
cout<<endl<<"do you want to play the quiz again:";
gets(iyon);
if(strcmp(iyon,"yes")==0||strcmp(iyon,"YES")==0)
{
cout<<endl<<"which quiz do you want to play:"<<endl<<"1-random quiz"<<endl<<"2-topic wise quiz"<<endl;
int shar;
cin>>shar;
if(shar==1)
goto pos1;
else
goto pos2;
}

}
}

Topic archived. No new replies allowed.