I am having a problem in my game which includes file handling for some quiz and entertainment. I am having this problem for more than a week and I seriously need to submit my program to the University this week.
/void quesengg()
{
ifstream file1("database/engineering.txt");
ifstream file11("database/enggans.txt");
for (int i=0;getline(file1,line1[i]);i++)
{
if (i==line_n)
{
getline(file1,line1[curr_line[i]]);
}
}
line_n+=2;
getline(file11,line22[0]);
}
void quessport()
{
ifstream file1("database/sports.txt");
ifstream file11("database/sportsans.txt");
for (int i=0;getline(file1,line1[i]);i++)
{
if (i==line_n)
{
getline(file1,line1[curr_line2]);
}
}
line_n22+=3;
getline(file11,line11[0]);
}
void quesmedical()
{
ifstream file1("database/medical.txt");
ifstream file11("database/medicalans.txt");
for (int i=0;getline(file1,line1[i]);i++)
{
if (i==line_n)
{
getline(file1,line1[curr_line]);
}
}
line_n+=2;
getline(file11,line11[0]);
}
void quesgk()
{
ifstream file1("database/gk.txt");
ifstream file11("database/gkans.txt");
for (int i=0;getline(file1,line1[i]);i++)
{
if (i==line_n)
{
getline(file1,line1[curr_line]);
}
}
line_n+=2;
getline(file11,line11[0]);
}
void ques(){
switch(Wwindow().QueBck)
{
case 1:
quesengg();
break;
case 2:
quessport();
break;
case 3:
quesmedical();
break;
default:
quesgk();
}
}
void show(){
void ques();
RenderWindow window(VideoMode (500,500),"!! Quiz !!");
while(window.isOpen())
{
Event event1,event;
while (window.pollEvent(event1))
{
if (event1.type == Event::Closed)
window.close();
}
if (Keyboard::isKeyPressed(Keyboard::Return))
{
if(texta.getString()== line11[0])
{
window.clear();
texta.setString("");
window.close();
}
}
if (event1.type == Event::TextEntered && done == false)
{
if (event1.text.unicode < 128 && event1.text.unicode !=0)
{
str1 = static_cast<char>(event1.text.unicode);
texta.setString(str1);
}
}
textq1.setString(line1[curr_line]);
textq2.setString(line1[curr_line+1]);
textq3.setString(line1[curr_line+2]);
// textq2.setString(line1[i+1]);
// textq3.setString(line1[i+2]);
window.draw(rect1);
window.draw(rect2);
window.draw(textq1);
window.draw(texta);
window.draw(textq2);
window.draw(textq3);
window.display();
}
curr_line+=3;
}
When I run this code , though I am calling the sports or medical or gk question , it only calls the engineering questions every time. What might be the problem?
Hoping to get positive response.