Largest Value in an Array + More

Hey guys, so I just started diving into Arrays. I'm about 3 weeks ahead of my class, assignment wise, so I've been teaching myself with online resources. I figured out how to calculate the largest "Test Score" in my Array, but I have no idea how I would go about displaying the First and Last name that corresponds to that Test Score. I can already tell as soon as I wrote the first case switch that this will not work.
I'm thinking I'm going to have to incorporate some of my own functions to get through this, but I'm not really sure how to go about it. I'd really appreciate it if anyone has some advice on how I should proceed.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <limits>
using namespace std;
int Grade[100];
string FirstName[100];
string LastName[100];
int numStudents, testTotal, testAvg, option, temp=0;


int main()
{
   cout << "*** Welcome to the Test Score Analyzer ***" << endl;
// Asks for number of students and check for valid range(1-100).
while ((cout << "How many Students do you have (1-100)?: ") &&
      (!(cin >> numStudents) || numStudents < 1 || numStudents > 100))
{
    cout << "That's not a number between 1 and 100; ";
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
// Reads in Student's First name and Last name.
for(int i = 0; i < numStudents; i++)
{
   cout << "Enter first name for student #" << i+1 << ": ";
   cin >> FirstName[i];
   cout << "Enter last name for student #" << i+1 << ": ";
   cin >> LastName[i];
   // Reads in Student's grade and checks for positive value.
   while ((cout << "Enter test score for student #" << i+1 << ": ") &&
         (!(cin >> Grade[i]) || Grade[i] < 1 ))
   {
       cout << "Test score cannot be less than 0; ";
       cin.clear();
       cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }
}
   // Presents menu to the user.
   cout << "*** Score Analyzer Main Menu ***" << endl;
   cout << "1. See highest score(s)" << endl;
   cout << "2. See lowest score(s)" << endl;
   cout << "3. See class average" << endl;
   cout << "4. See students below class average" << endl;
   cout << "5. See students at or above class average" << endl;
   cout << "6. See all students" << endl;
   cout << "7. Exit system" << endl;
   // Reads in user's choice and checks for valid option (1-7)
   while ((cout << "Please select an option from the menu: ") &&
         (!(cin >> option) || option < 1 || option > 7))
   {
       cout << "Your selection is invalid; ";
       cin.clear();
       cin.ignore(numeric_limits<streamsize>::max(), '\n');
   }
switch (option)
{
   case 1:
      for(int i = 0; i < numStudents; i++)
      {
        if (Grade[i] > temp)
           temp = Grade[i];
      }
      cout << "The highest grade is: " << temp << endl;
}

}
Or maybe someone could point me to a resource that would teach me how to do this. I've read about multiple dimensional arrays, but I'm not sure if that's the solution, I think I would encounter the same problem I'm having now.
When finding the highest grade, you need to store the index of which element in the array contained that highest value. Then at the end, you can use that index to access all three of your arrays.
Woohoo! Thanks a bunch, Chervil!
Last edited on
Topic archived. No new replies allowed.