This was my assignment.

> 
> Write a C++ program that reads in a series of test scores. If the test score is >= 90 && , <= 100; print the letter grade 'A'. If the score is >= 80 but < 90, print the letter grade 'B'. if the test score is >= 70 and < 80, print the letter grade 'C'. If the test score is >= 60 but < 70 print the letter grade 'D' If the test score is < 60 print the letter grade 'F'. Print the score and the corresponding grade. Determine and print the max score, the min score, the average score, and the number of tests. Terminate on a negative test score.
> 
> 
> 

My code works fine but I feel like there's a better way to do it. I talked to a friend and he said since I was reading from a file a array would be better. How would I got about that?

```
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
    ifstream inFile;

    int Score, MaxScore, MinScore, AvgScore, NumTests, TotalScore, Num;
    string Grade;

    NumTests = 0;
    TotalScore = 0;
    MaxScore = 0;
    MinScore = 100;

    inFile.open("indata6.txt");

    if (!inFile)

    {
        cout << "Failed to find inFile." << endl;
        return 1;
    }

    cout << "Test Scores & Grades" << endl;
    cout << "--------------------" << endl;

    while ( inFile >> Score)

    {
        NumTests = NumTests + 1; // Setting number of tests
        TotalScore = TotalScore + Score; // Adding the Total score for the Avg equation

        if ( Score > MaxScore) // If statements to find Max score
        {
            MaxScore = Score;

            if ( Score >= 90 &&  Score <= 100) // If statements to find letter Grades
            {
                Grade = "A";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 80)
            {
                Grade = "B";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 70)
            {
                Grade = "C";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 60)
            {
                Grade = "D";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 0)
            {
                Grade = "F";
                cout << Score << " " << Grade << endl;
            }

            else
            {
                cout << "Invalid Test Score:" << Score << endl;
                return 2; 
            }

        }

        else if ( Score < MinScore) // If statement to find Min score
        {
            MinScore = Score;

            if ( Score >= 90 &&  Score <= 100) // If statements to find letter grades
            {
                Grade = "A";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 80)
            {
                Grade = "B";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 70)
            {
                Grade = "C";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 60)
            {
                Grade = "D";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 0)
            {
                Grade = "F";
                cout << Score << " " << Grade << endl;
            }

            else 
            {
                cout << "Invalid Test Score:" << Score << endl;
                return 2;
            }
        }

        else // When a score isnt Max or Min
        {   
            if ( Score >= 90 &&  Score <= 100) // More if statements to find letter grade
            {
                Grade = "A";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 80)
            {
                Grade = "B";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 70)
            {
                Grade = "C";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 60)
            {
                Grade = "D";
                cout << Score << " " << Grade << endl;
            }

            else if ( Score >= 0)
            {
                Grade = "F";
                cout << Score << " " << Grade << endl;
            }

            else 
            {
                cout << "Invalid Test Score:" << Score << endl;
                return 2;
            }
        }
    }

    AvgScore = TotalScore / NumTests; // Finding the avg test score

    cout << "Max Score: " << MaxScore << endl; // Printing Max score
    cout << "Min Score: " << MinScore << endl; // Printing Min score
    cout << "Avg Score: " << AvgScore << endl; // Printing Avg score
    cout << "Number of Tests: " << NumTests << endl; // Printing Number of Tests

    return 0;
}

```