Not quite sure where I'm going wrong. It's not outputting anything when I execute so I'm assuming its stuck somewhere and goes on endlessly. Assignment is as follows -- "Write a program that reads a file consisting of students' test scores in the range 0-200. It should then determine the number of students having scores in each of the following ranges: 0-24,25-49,50-74,75-99,100-124,125-149,150-174,175-200. Output the input data."
#include "stdafx.h"
#include "iostream"
#include "fstream"
using namespace std;
int main()
{
ofstream outFile;
ifstream inFile;
int num;
int category[8] = { 0,0,0,0,0,0,0,0 };
outFile.open("testscores.txt");
if (!outFile)
{
cout << "outFile open failed." << endl;
return 0;
}
outFile << "blah blah" << endl << endl;
inFile.open("scorestest.txt");
if (!inFile)
{
cout << "infile failed" << endl;
return 0;
}
inFile >> num;
while (!inFile.eof())
{
if (num < 25)
category[0]++;
else if (num < 50)
category[1]++;
else if (num < 75)
category[2]++;
else if (num < 100)
category[3]++;
else if (num < 125)
category[4]++;
else if (num < 150)
category[5]++;
else if (num < 175)
category[6]++;
else if (num < 200)
category[7]++;
}
for (int i = 0; i <= 7; i++)
{
cout << "Number of Grades between" << category[i] << endl;
outFile << "Number of Grades between" << category[i] << endl;
}
inFile.close();
outFile.close();
return 0;
}
Been struggling on this for a bit. Is it perhaps my inFile? I've rewrote different code three times to get this program to work with no luck