Increase the size of an array by one for each entry

Viewed 64

So for an assignment, I am working on I need to be able to make my code below meet the following specification. I have it so a user can choose a predetermined size for the array to store entries/test scores.

Start your array at size 0 and increase it by one every time you add a new score with menu option 1.

void GetChoice(Grade &student)
{
    cout << "Enter your selection: ";
    cin >> student.userChoice;

    if (student.userChoice == 1) {
        GetScores(student);
        ProgramMenu(student);
    }
    else if (student.userChoice == 2)
    {
        DisplayStudentStats(student);
        ProgramMenu(student);
    }
    else if (student.userChoice == 3)
    {
        DisplayStudentStats(student);
        cout << "Student GPA: " << ProcessScores(student) << " ";
        FindGPA(student);
        cout << student.GPA << endl;
        ProgramMenu(student);
    }
    else if (student.userChoice == 4)
    {
        exit(0);
    }
    else 
    {
        cout << "Please enter 1, 2, 3 or 4" << endl;
        GetChoice(student);
    }
    
}

void GetScores(Grade &student)
{
    int count = 0; // counter 
    double score = 0; // holder for input
    cout << "How many test scores would you like to enter for ID# "
        << student.studentID << "? ";
    cin >> student.size; // deliberate choice for the size of both arrays below
    student.grades = new double[student.size] {}; // Array
    student.letters = new char[student.size] {}; // initialization
    while (count != student.size) {
        cout << "Enter a grade: ";
        cin >> score; // Test score input
        student.grades[count] = score; // Feeding in each test score
        if (score == 0) { // If input is zero return to main menu 
            break;
        }
        count++;
    }   
}

Any tips to point me in the right direction would be helpful?

0 Answers
Related