# Answer to Question #27744 in C++ for matthew

Question #27744

Write a program that prompts the user to enter the number of students and each student's score, then finally displays the highest score. The more simple it is the better, thank you.

Expert's answer

#include <iostream>

using namespace std;

/* Reads the number of students, each student's score

& * and returns the number of students entered */

int input_scores(float* (&scores))

{

int studentCount;

/* Input the number of students */

cout << "Enter the number of students: ";

cin >> studentCount;

/* Allocate memory for the array of scores */

scores = new float[studentCount];

/* Input student scores */

cout << "Enter " << studentCount << " scores: ";

for (int c = 0; c < studentCount; c++)

cin >> scores[c];

return studentCount;

}

/* Returns the highest score from the given array of scores */

float find_highest_score(float* scores, int count)

{

if (count == 0)

return -1;

float maxScore = scores[0];

for (int k = 1; k < count; k++)

if (scores[k] > maxScore)

maxScore = scores[k];

return maxScore;

}

int main()

{

float* scores;

int scoreCount = input_scores(scores);

cout << "The highest score is: "

<< find_highest_score(scores, scoreCount) << endl;

return 0;

}

using namespace std;

/* Reads the number of students, each student's score

& * and returns the number of students entered */

int input_scores(float* (&scores))

{

int studentCount;

/* Input the number of students */

cout << "Enter the number of students: ";

cin >> studentCount;

/* Allocate memory for the array of scores */

scores = new float[studentCount];

/* Input student scores */

cout << "Enter " << studentCount << " scores: ";

for (int c = 0; c < studentCount; c++)

cin >> scores[c];

return studentCount;

}

/* Returns the highest score from the given array of scores */

float find_highest_score(float* scores, int count)

{

if (count == 0)

return -1;

float maxScore = scores[0];

for (int k = 1; k < count; k++)

if (scores[k] > maxScore)

maxScore = scores[k];

return maxScore;

}

int main()

{

float* scores;

int scoreCount = input_scores(scores);

cout << "The highest score is: "

<< find_highest_score(scores, scoreCount) << endl;

return 0;

}

## Comments

## Leave a comment