-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorestat.cpp
More file actions
41 lines (36 loc) · 1.55 KB
/
Copy pathscorestat.cpp
File metadata and controls
41 lines (36 loc) · 1.55 KB
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
#include <iostream>
#include <string>
using namespace std;
int main() {
const int ARRAY_LEN = 5; // Number of elements in array
string names[ARRAY_LEN]; // Array of names
int scores[ARRAY_LEN]; // Array of test scores
int sum = 0; // Sum of all test scores
int maxScore = 0; // Maximum test score
int minScore = 100; // Minimum test score
string maxName, minName; // Names associated with max and min scores
// Read names and scores from the user
cout << "Enter " << ARRAY_LEN << " names and test scores:" << endl;
for (int i = 0; i < ARRAY_LEN; i++) {
cout << "Name " << (i + 1) << ": ";
cin >> names[i];
cout << "Score " << (i + 1) << ": ";
cin >> scores[i];
sum += scores[i];
if (scores[i] > maxScore) { // Find maximum score
maxScore = scores[i];
maxName = names[i];
}
if (scores[i] < minScore) { // Find minimum score
minScore = scores[i];
minName = names[i];
}
}
// Calculate average
double average = static_cast<double>(sum) / ARRAY_LEN;
// Output results
cout << "Maximum score: " << maxScore << " by " << maxName << endl;
cout << "Minimum score: " << minScore << " by " << minName << endl;
cout << "Average score: " << average << endl;
return 0;
}