I'm working on a program that reads a file of scores and then outputs the number of scores in certain ranges. I've got it to read the input file (scores.txt) which is set up as follows; 76 89 150 135 200 76 12 100 150 28 178 189 167 200 175 150 87 99 129 149 176 200 87 35 157 189
there are 8 different score ranges and I need to output how many scores are in each range. So far I'm using one range to make sure I figure this thing out. I'm very new to programming. It works if the first number is within the range, but that's as far as it gets. if the first number in the file is not within the range, it outputs nothing. I am totally lost, I'm not sure I'm even going about this the right way. Any ideas?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX_CODE_SIZE = 50;
void readCode(ifstream& infile, int list[], int& length, bool& lenCodeOk);
int main()
{
int codeArray[MAX_CODE_SIZE];
int codeLength;
bool lengthCodeOk;
ifstream incode;
incode.open("scores.txt");
if (!incode)
{
cout << "Can't open the input file" << endl;
return 1;
}
readCode (incode, codeArray, codeLength, lengthCodeOk);
incode.close();
return 0;
}
void readCode(ifstream& infile, int list[], int& length, bool& lenCodeOk)
{
int count;
int value;
int rangeA;
lenCodeOk = true;
infile >> length;
if (length > MAX_CODE_SIZE)
{
lenCodeOk = false;
return;
}
rangeA = 0;
value = 0;
for (count = 0; count < length; count++)
infile >> list[count];
{
value = list[count];
if (value >= 0 || value <= 24)
{
rangeA = rangeA + 1;
}
else
{
rangeA = rangeA;
}
}
cout << "The number of students with scores 0 - 24 are: " << rangeA << endl;
cout << endl;
}