I have a problem with this source code:
every time it reaches a file that cannot be found the next file even though it is there gives an error message to.
Please help.
DirX
(deu to problems with my website i have to post the code here)
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
int main()
{
int Random0to16 = 0, Check = 0, counter = 1, Correct = 0, Wrong = 0;
int QeustionsAnswered = 0;
int temp;
double Percent;
char file[9], AnswerCorrect[20], AnswerUser[20], Qeustion[125];
ifstream fin;
file[0] = 'q';
while(1)
{
counter++;
if (counter > 0 && counter <= 10)
file[1] = 't';
else if(counter > 10 && counter <= 20)
file[1] = 'm';
else if(counter > 20 && counter <= 30)
file[1] = 'w';
else if(counter > 18)
{
break;
}
srand(time(NULL));
Random0to16 = rand()%16;
Check = Random0to16/10;
file[2] = (Check + 1 + 48);
file[3] = Random0to16 - (Check * 10) + 48;
temp = rand()%6 + 1 + 48;
file[4] = temp;
file[5] = '.';
file[6] = 't';
file[7] = 'x';
file[8] = 't';
file[9] = '\0';
fin.open(file, ios::nocreate);
if(fin)
{
fin.getline(AnswerCorrect, 20);
while(!fin.eof())
{
fin.getline(Qeustion, 125);
cout << endl << endl << Qeustion << endl;
}
cin.getline(AnswerUser, 20);
fin.close();
if( !strcmpi(AnswerCorrect, AnswerUser) )
{
cout << "Your answer was correct!" << endl;
QeustionsAnswered++;
Correct++;
}
else if( strcmpi(AnswerCorrect, AnswerUser) )
{
cout << "Your answer was Wrong!" << endl;
cout << "The correct answer was: " << AnswerCorrect << endl;
QeustionsAnswered++;
Wrong++;
}
}
else if(!fin)
{
cout << "Fatal Error! " << endl;
cout << "Could open file: " << file << endl;
cout << "Press enter to continue... " << endl;
getchar();
fin.close();
continue;
}
}
if(QeustionsAnswered == 0)
cout << "No qeustions Answered therefor no score..";
else
{
Percent = (100.0 / QeustionsAnswered) * Correct;
cout << "\nYou have finished the Quiz!" << endl;
cout << "You had " << Percent << "% of the qeustions correct!" << endl;
}
return 0;
}