Entered values arent being saved/updated

For one of my assignment questions, it states
When Enter Mark is selected from the main menu, if the student ID supplied by the user already exists in the records, then the program will not try to read the corresponding mark and will abort this action and return to the main menu. Otherwise, the user will be allowed to enter a new student record(ID and mark).

Here is my coding
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <string>
using namespace std;

struct StudentRecord
     {
       string studentID;
       float studentMark;
       char studentGrade;
     } student;

void populate(StudentRecord *);
void dispOne(StudentRecord *);
int linearSearch (StudentRecord*student,const string id,int totalStudents);

int main()
{
    int menu;
    StudentRecord student[] =
                  {
                  {"P1001",78.50,'D'},
                  {"P1002",66,'C'}
                  };
    StudentRecord *recPoint;
    int totalStudents=2;
    float totalMarks;
    float averageMark;
    string id;
    int found;
   
    cout << "MAIN MENU\n"
         << "0. Exit         1. Statistics\n"
         << "2. Enter mark   3. Find mark\n"
         << "------------------------------\n"
         << "Your choice -> ";
    cin >> menu;
  while (menu != 0)
  {
    switch (menu)
    {
           case 1:
                totalMarks=0;
                for(int j=0;j<totalStudents;j++)
                    totalMarks+=student[j].studentMark;
                    averageMark=totalMarks/totalStudents;
                    cout << "Number of records: " << totalStudents <<endl;
                    cout << "Mean or average: " << averageMark <<endl;
                break;
           case 2:
                cout << "Enter a Student Record: " <<endl;
                cout << "Student ID -> ";
                cin >> id;
                found = linearSearch(student,id,totalStudents);
                if (found!=-1)
                  {
                    cout << "Record already exisists" << endl;
                  }
                else
                  {
                    id = cin.get();
                    recPoint = new StudentRecord;
                    populate(recPoint);
                    dispOne(recPoint);
                  }            
                break;
           case 3:
                cout << "Find marks for ID -> ";
                cin >> id;
                found = linearSearch(student,id,totalStudents);
                if(found!=-1)
                  {
                    cout << "-------------" << endl;
                    cout << "Student ID: " << student[found].studentID << endl;
                    cout << "Mark/Grade: " << student[found].studentMark << " (" << student[found].studentGrade << ")" << endl;
                    cout << "-------------" << endl;
                  }
                else
                  cout << "Record does not exist" << endl;          
                break;
           default:
                cout << "Invalid selection. Please make a selection between 0-3.\n"
                     << endl;
                break;
    }    

    cout << "MAIN MENU\n"
         << "0. Exit         1. Statistics\n"
         << "2. Enter mark   3. Find mark\n"
         << "----------------------------\n"
         << "Your choice -> ";
    cin >> menu;
  }
system("Pause");
return 0;
}

void populate(StudentRecord *record)
{
     cout << "Enter a Student ID: ";
     getline(cin,record->studentID);
     cout << "Enter the corresponding mark: ";
     cin >> record->studentMark;
     return;
}

void dispOne(StudentRecord *contents)
{
     cout << "\nThe contents of the record just created is:"
          << "\nStudent ID: " << contents->studentID
          << "\nMark: " << contents->studentMark << endl;
          return;
}

int linearSearch(StudentRecord*student,const string id,int totalStudents)

{
    int retValue=-1;
    for(int i=0;i<totalStudents;++i)
    {
            if(student[i].studentID == id)
            {
              retValue=i;
              break;
            }
    }
    return retValue;
}


I have notice that the new records entered have not actually been saved. For example, after I have entered values for the new record, when I select the statistics mark to check for the average mark, the number of records still remain at 2 instead of 3. And the average mark is still 72.25. Also, when I try to display the new record, it displays "record does not exist".

What could be wrong?
Well nowhere in your code does it ever make an attempt to save the new record in your student array. But even if you wanted to, it wouldn't really work because its an array, which can't grow in size. Store your students in a vector, then you can insert a new student with students.push_back(student);.

Reading material
http://www.cplusplus.com/reference/stl/vector/
Topic archived. No new replies allowed.