Hello, I am having trouble with calling a file. ifstream inFile ("index.txt"); program runs but it wont call the index.txt file
// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <string.h>
using namespace std;
int main()
{
int totalQuestion;
int totalPoints = 0;
string input, type, question, answer;
int totalOptions;
string c;
int points;
ifstream inFile ("index.txt");
if (inFile.is_open())
{
inFile >> totalQuestion;
while(true)
{
for (int i = 0; i < totalQuestion; ++i)
{
cout << "Question: "<< (i+1) << endl;
inFile >> type >> points;
// read type of question
if(type == "TF")
{
// get the question
inFile.ignore();
getline(inFile, question);
// get the answer
inFile >> answer;
cout << "Question: " << question << endl;
cout << "Input answer: ";
cin >> input;
if(input == answer)
{
cout << "Right Answer\n\n";
totalPoints = totalPoints + points;
}
else
cout << "Wrong answer\n\n";
}
else if(type == "MC")
{
string options;
inFile.ignore();
getline(inFile,question);
inFile >> totalOptions;
cout << "Question: " << question << endl;
for (int j = 0; j < totalOptions; ++j)
{
getline(inFile , options);
cout << options << endl;
}
inFile >> answer;
cout << "Enter your choice(A-F): ";
cin >> c;
inFile.ignore();
if(c == answer)
{
cout << "Right Answer\n\n";
totalPoints = totalPoints + points;
}
else
cout << "Wrong answer\n\n";
}
if(inFile.eof())
break;
}
}
inFile.close();
}
else cout << "Unable to open file";
cout << "Total points: " << totalPoints << endl;
return 0;
}
/*
index.txt
3
TF 5
There exist birds that cannot fly?
true
MC 10
Who was the President of the USA in 1991?
6
Richard Nixon
Gerald Ford
Jimmy Carter
Ronald Reagan
George Bush Sr.
Bill Clinton
E
TF 10
The city of Boston hosted the 2004 Summer Olympics?
false
*/