I wrote a program for class but it never runs correctly, it just gives me that blank black screen with a blinking cursor. The .txt file is in the Resource Files. Any idea why it's having issues? I'm using Visual Studio 2015.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream finput("mp2accept.txt");
char school;
double GPA;
int math, verbal;
char alumni;
int SAT;
int i = 0;
int countLA = 0;
int countM = 0;
while (!finput.eof())
{
finput >> school >> GPA >> math >> verbal >> alumni;
SAT = math + verbal;
if (school == 'L')
{
cout << "Applicant#:"<<i+1;
cout << "\nSchool: Liberal Arts\n";
cout << "GPA: " << GPA << endl;
cout << "SAT Score: " << SAT << endl;
cout << " Alumni: " << alumni << endl;
cout << "Result: ";
i++;
}
if (school == 'M')
{
cout << "Applicant#:"<<i+1;
cout << "\nSchool: Music\n";
cout << "GPA: " << GPA << endl;
cout << "SAT Score: " << SAT << endl;
cout << "Alumni: " << alumni << endl;
cout << "Result: ";
i++;
}
if (alumni == 'Y')
{
if(SAT < 1000)
{
cout << "Rejected - SAT is too low\n\n";
continue;
}
if (GPA < 3)
{
cout << "Rejected - GPA is too low\n\n";
continue;
}
}
else if (alumni == 'N')
{
if (SAT < 1200)
{
cout << "Rejected - SAT is too low\n\n";
continue;
}
if (GPA < 3.5)
{
cout << "Rejected - GPA is too low\n\n";
continue;
}
}
if (school == 'L')
{
if (countLA < 5)
{
cout << "Accepted into Liberal Arts!!\n\n";
countLA++;
continue;
}
else
{
cout << "Rejected - Seats filled for Liberal Arts\n\n";
continue;
}
}
else if (school == 'M')
{
if (countM < 3)
{
cout << "Accepted into Music!!\n\n";
countM++;
continue;
}
else
{
cout << "Rejected, Seats filled for Music\n\n";
continue;
}
}
}
finput.close( );
return 0;
}
***************************
Data File:
L 4.0 600 650 N
M 3.9 610 520 N
L 3.8 590 600 N
L 3.0 600 600 Y
L 3.4 600 600 N
L 3.0 500 490 Y
L 2.9 500 500 Y
M 3.5 500 490 Y
M 3.9 490 600 Y
L 3.5 700 500 N
L 3.1 600 400 Y
L 3.0 490 510 Y
L 4.0 800 800 Y
M 3.2 500 500 N
guessing that your file failed to open, which would bypass all the code.
As said, add some prints ... specifically, if file.eof() is true right after opening, print something.
visual studio is bad about shifting folders and breaking input file path when run from the IDE it is different from when double clicked or kicked off from command line. You may want to code the path into the file name if using VS.