Array Implementation

Hello,
i have to do that :
Write a program to read class grades from a file (A5Q3.dat - which is given to you) into an array grades and to then output to the screen the following information:
Class Average
Percentage of grades >= 90
Percentage of grades < 90 and >= 80
Percentage of grades < 80 and >= 65
Percentage of grades < 65 and >= 50
Percentage of grades < 50
Show average and percentages accurate to 2 places after the decimal (xx.xx and xx.xx%).
I need to put them into functions, but i will do that if i have the correct code, but can't seem to resolve it.
what i was able to do until now is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
#include <fstream>

using namespace std; 


int main()
{

    
    
	ifstream iFile("A5Q3.txt");//input file
	ofstream oFile("A5Q3O.txt");//output file
	string iLine;
    int grade=100;
    int record[grade];
    double percent;
    int count=0;
    int sum;
    
    if (iFile.good() && oFile.good()) //if file is opening
    {	
        while(getline(iFile, iLine)) //read line by line
        {
            int size = iLine.length();
            
            for(grade=0;grade<=size;grade++)
            {
                for(count=0;count<=size;count++)
                {
                if (grade>=90) 
                {
                    percent = (sum+=grade)/(count);
                    cout<<percent<<"%";
                } 
                else if(grade>=80 && grade<90) 
                {
                    percent = (sum+=grade)/(count);
                    cout<<percent<<"%";
                }
                else if(grade>=65 && grade<80) 
                {
                    percent = (sum+=grade)/(count);
                    cout<<percent<<"%";
                }
                else if(grade>=50 && grade<65) 
                {
                    percent = (sum+=grade)/(count);
                    cout<<percent<<"%";
                }
                else if (grade<50) 
                {
                    percent = (sum+=grade)/(count);
                    cout<<percent<<"%";
                }
                }
                
            }
            
            
        }//END OF WHILE
        cout<<endl;
        cout<<"The files are now closed. "<<endl;
        cout<<"You can see the text in reverse in the file A3Q3O.txt. "<<endl;
        iFile.close();
        oFile.close();
    }//END OF IF FOR FILES OPENING.
    else 
        cout<<"Error, can't open the input file. "<<endl;//if can't open file error msg.
    return 0;
}//END OF MAIN 


Thanks for any help.

this is what is inside the file:
55 56 90 88 34 10 0 67 76 55
81 87 72 68 73 77 97 80 85 73
33 62 74 76 91 83 84 79 88 79
I was able to get to that for now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <fstream>

using namespace std;
/*
void getdata();
double calculate();
void show();
*/

int main()
{

     ifstream iFile("A5Q3.dat");
     string iLine;
     int i=0;
     int grade[i];
     int avg;
     int sum;
     int count=0;
     
     if(iFile.good())
     {
        //while(getline(iFile,iLine))
        //{
          // cout<<iLine<<endl;
           
           iFile>>grade[i];
           
           while(!iFile.eof())
           {
              iFile>>grade[i];
              
              for(i=0;i<=100;i++)
                {
                  if(grade[i]>=90)
                     {count++;
                     sum=grade[i]/count;
                     cout<<"Sum= "<<sum;}
                  else if(grade[i]<90 && grade[i]>=80)
                     {count++;
                     sum=grade[i]/count;
                     cout<<"Sum= "<<sum;}
                  else if(grade[i]>80 && grade[i]>=65)
                     {count++;
                     sum=grade[i]/count;
                     cout<<"Sum= "<<sum;}
                  else if(grade[i]>65 && grade[i]>=50)
                     {count++;
                     sum=grade[i]/count;
                     cout<<"Sum= "<<sum;}
                  else if(grade[i]<50)
                     {count++;
                     sum=grade[i]/count;
                     cout<<"Sum= "<<sum;}
                }                   
           }
           
        
     }
     else 
          cout<<"Error."<<endl;
     
system("pause");
}
need help please.
can't figure out how to do this.
i got this for now
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define SIZE 100
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

float getScores (ifstream &, float[]);



int main()
{
    
    int count=0;
    float score[SIZE]={0}, average, scoretotal=0;
    string filename;
    ifstream fin;
    
    
    fin.open("File.rtf");
    if (fin.fail())
        cout<<"\nError opening file.\n";
    else
    {
        
        getScores (fin, score);
        
       
        
        cout<<"============================";
        
        
        cout<<"\n\n\tStatistics";
        cout<<"\n~~~~~~~~~~~~~~~~~~~~~";
        
        cout<<"Number of scores\t="<<count<<endl;
        
        cout<<"Average\t\t\t="<<average<<endl;
    }
    
}



float getScores (ifstream & fin, float score[])
{
    int count=0, i=0;
    float avg;
    
    fin>>score[i];
    
    while (!fin.eof())
    {
        
        if(score[i]>=90)
        {
            
            fin>>score[i];
            count++;
            
            avg=score[i]/count;
            
            
            
        }if (count == SIZE)
        {
            cout<<"Array is full.\n";
            break;
        }
    }
    return (avg);
}
}
Topic archived. No new replies allowed.