edit here's what's on the file
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
I want help with something pretty simple. Below is a program that reads a text file with a number of grades on it. The program takes those numbers, stores them in an array, then determines what category they belong in, hence the setCategories function I've written. Once it sets the categories the number of each number in a category is stored in an array and that array is printed to another text file. Or at least it's supposed to - as of right now I don't have the getData and printData functions defined, which are the two I have positioned to do all the leg work/ I need some help writing these functions, for some reason I can't seem to wrap my head around them.
#include <iostream>
#include <fstream>
using namespace std;
void getData(istream & in, int A[], int & count)
{
while(!in.eof())
{
in >> A[count++];
}
}
void printData(ostream & out, int ctd[], int count)
{
for (int i=0; i < count; i++)
{
out << ctd[i] << endl;
}
}
void setCategories(int c[], int g[], int size) {
int i;
for (i = 0; i < size; i++) {
if (g[i] > 174)
c[7]++;
else if (g[i] > 149)
c[6]++;
else if (g[i] > 124)
c[5]++;
else if (g[i] > 99)
c[4]++;
else if (g[i] > 74)
c[3]++;
else if (g[i] > 49)
c[2]++;
else if (g[i] > 24)
c[1]++;
else c[0]++;
}
}
int main() {
ofstream outFile;
ifstream inFile;
int categories[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int grades[40];
int count = 0;
inFile.open("/Users/holdentatlow/Desktop/computer_science_projects/test_scores.txt");
outFile.open("/Users/holdentatlow/Desktop/computer_science_projects/results.txt");
outFile << "Matthew Holden Tatlow" << endl;
getData(inFile, grades, count);
setCategories(categories, grades, count);
printData(outFile, categories, count);
return 0;
}
Right now, my output file is pure nonsense:
Matthew Holden Tatlow
1
2
0
6
1
3
5
8
262169208
1
0
0
262169416
1
-1196213792
32767
-520085504
32712
-520085410
32712
-520085410
32712
0
0
0
0