The question is attached and so I've tried to solve this but the output I'm getting is large numbers which is probably garbage data and therefore is definitely not correct.
Here is my code
#include <iostream>
#include <fstream>
using namespace std;
const int size=8;
void readData(char filename[], int list[], int size)
{
ifstream fin;
fin.open("HW4_Q1data.txt");
int value=0;
for(int i=0;i<30;i++)
{
fin>>filename[i];
value=filename[i];
if (value >= 0 && value <= 24)
list[0]++;
else if (value >= 25 && value <= 49)
list[1]++;
else if (value >= 50 && value <= 74)
list[2]++;
else if (value >= 75 && value <= 99)
list[3]++;
else if (value >= 100 && value <= 124)
list[4]++;
else if (value >= 125 && value <= 149)
list[5]++;
else if (value >= 150 && value <= 174)
list[6]++;
else if (value >= 175 && value <= 200)
list[7]++;
}
fin.close();
}
void print(int list[], int size)
{
cout << " Range"<<'\t'<<"# of students"<<endl;
cout << "0-24: " <<'\t'<<list[0] << endl;
cout << "25-49: " << '\t'<<list[1] << endl;
cout << "50-74: " <<'\t'<< list[2] << endl;
cout << "75-99: " <<'\t'<< list[3] << endl;
cout << "100-124: " <<'\t'<< list[4] << endl;
cout << "125-149: " <<'\t'<<list[5] << endl;
cout << "150-174: " <<'\t'<< list[6] << endl;
cout << "175-200: " <<'\t'<< list[7] << endl;
}
int main()
{
char filename[70];
int list[size];
readData(filename,list,size);
print(list,size);
return 0;
}