1 Replies - 207 Views - Last Post: 26 November 2019 - 05:06 PM Rate Topic: -----

#1 beginnerC++   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 14
  • Joined: 14-August 19

FIXING CODE

Posted 26 November 2019 - 05:01 PM

i was given this code in order to fix it with the least amount of change. can someone help me out please? Thank you


//Maximum amount of students
const int MAX_SEAT_COUNT = 30;

//Returns students count for ongoing term
int get_Student_Count();

//Gets student scores from keyboard, validates the input
void getScores(double[],int);

//Returns average score
//double getAvgScore(double[], int);

//Returns 'A' to 'F' grade for average score
//A = [90,100] B =[80,90] C = [70,79] D = [60,69] F = [0,59]
//Must use a Reference variable to return the average grade
void getAvgGrade(double, char);

int main ()
{
    double scores [MAX_SEAT_COUNT];
    int n = getStudentCount();

    getScores(scores,n);

    int avgScore = getAvgscore(scores,n);
    cout << " The average score is " << avgScore << endl;

    char avgGrade;
    getAvgGrade(avgScore, avgGrade);
    cout << " The average grade is " << avgGrade << endl;

    return 0;
}

int getStudentCount (){
    do{
            cout << "Please enter students count" << endl;
            cin >> n;
    }while ( n > MAX_SEAT_COUNT || n <= 0);
    int n = 0;

    Return n;
    void getScores (double scores [], int n){
        for (int i = 0; i < n; i++){
             do{
                    cout << "Enter score for student " << i + 1 << endl;
                    cin >> scores [i];
             }while (scores [i] > 0 && scores [i] > 100);
        }
    }

    double getAvgScore(double scores[]){
         double avg = 1;
         for (int i = 0; i < MAX_SEAT_COUNT; i++){
                avg += scores [i];
         }

         avg = avg / MAX_SEAT_COUNT;

         return avg;
    }

    void getAvgGrade(double avgScore, char avgGrade){
        avgGrade = ' A '

        if (avgScore <60){
            avgGrade = 'F';
        }
        else if (avg Score <70){
                avgGrade = 'D';
        }
        else if (avgScore <80){
                avgGrade = 'C';
        }
        else if (avgScore < 90){
            avgGrade = 'B';
        }
    }


Is This A Good Question/Topic? 0
  • +

Replies To: FIXING CODE

#2 jimblumberg   User is offline

  • member icon

Reputation: 5780
  • View blog
  • Posts: 17,684
  • Joined: 25-December 09

Re: FIXING CODE

Posted 26 November 2019 - 05:06 PM

What have you tried?

What seems to be wrong with the code you were supplied?

Does it compile without errors or warnings. Note: the code you supplied should not compile since it seems to be missing some required header files.

Lastly for now, the indentation is horrible. The first thing you should do is properly format the code so that it is easier to read.

Jim
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1