Hi guys, what I'm trying to do is allow the user to add a new student record to the system. If the user inputs a student ID already existing in the system, it doesn't accept the ID, but if it's a new student ID, it asks the user if they want to add the student to the system. When the user opts 'Y', it crashes! It's not supposed to! Here's the relevant code:

case 6://add a student record
        {
        int first = 0;
        int last = NUMRECS;
        int mid;
        int studentCount, newStdCourseCode, newStdCreditPoint;
        studentCount = NUMRECS;
        char decision3, option2, optAgain5, optAgain6, optAgain7, optAgain8, optAgain9, optAgain10, optAgain11, optAgain12;
        string newStdName;
        do
        {
        cout << "Please type in the student ID number\nof the student you want to input,\nthen press enter.\n";
        cin >> stdIDInput;
        bool found = false;
        while (first <= last && !found)//checks if there's a match
        {
            mid = (first + last)/2;
            if (stdRec[mid].studentID == stdIDInput)
            {
                found = true;
                cout << "This student ID already exists in the system.\n";
                cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
                cout << setiosflags(ios::left);
                cout << setw(12) << stdRec[mid].studentID
                     << setw(21) << stdRec[mid].studentName
                     << setw(13) << stdRec[mid].courseCode
                     << setw(5)  << stdRec[mid].creditPoint << endl;
            }
            else if (stdRec[mid].studentID > stdIDInput)
            {
                last = mid -1;
            }
            else
            {
                first = mid +1;
            }
        }
        if (!found)
        {
            cout << "Would you like to add the student to the records? Y/N\n";
            cin >> decision3;
            if(decision3 == 'Y')//***HERE!!! This is when it crashes if you opt 'Y' and I don't know how to fix it!
            {
                last = NUMRECS;
                studentCount++;
                if((stdIDInput > "17000010") && (stdIDInput < "99999999"))
                {
                    stdRec[last+1].studentID = stdIDInput;
                    cout << "Please input the new student's name.\n";
                    getline (cin, newStdName);
                    stdRec[last+1].studentName = newStdName;
                    do
                    {
                        cout << "\n\nPlease input the new student's course code (the SCM offers courses 3506, 3633, 3634 \nand 3639).\n";
                        cin >> newStdCourseCode;
                        
                        if ((newStdCourseCode == 3506) || (newStdCourseCode == 3633) || (newStdCourseCode == 3634) || (newStdCourseCode == 3639)) 
                        {
                            stdRec[last+1].courseCode = newStdCourseCode;
                        }
                        else
                        {
                            cout << "Not a valid course code. SCM only offers courses 3506, 3633, 3634 or 3639.\n"
                                 << "Would you like to try again? Y/N";
                            cin >> optAgain5;
                            if(optAgain5 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain5 = 'Y');
                    
                    do
                    {
                        cout << "Please input the new student's credit points. Valid credit points can range from 0-240 as multiples of 10.\n";
                        cin >> newStdCreditPoint;
                        if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))
                        {
                            stdRec[last+1].creditPoint = newStdCreditPoint;
                        }
                        else
                        {
                            cout << "Not a valid credit point. Valid credit points can range from 0-240 as multiples of 10.\n"
                                 << "Would you like to try again? Y/N\n";
                            cin >> optAgain9;
                            if (optAgain9 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain9 = 'Y');
                    
                    cout << "The student's information has now been added to the records.\n";
                    cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
                    cout << setiosflags(ios::left);
                    cout << setw(12) << stdRec[last+1].studentID
                         << setw(21) << stdRec[last+1].studentName
                         << setw(13) << stdRec[last+1].courseCode
                         << setw(5)  << stdRec[last+1].creditPoint << endl;
                }
                if((stdIDInput > "16666666") && (stdIDInput < "17000010"))
                {
                    stdRec[last+1].studentID = stdRec[last].studentID;
                    stdRec[last+1].studentName = stdRec[last].studentName;
                    stdRec[last+1].courseCode = stdRec[last].courseCode;
                    stdRec[last+1].creditPoint = stdRec[last].creditPoint;
                    stdRec[last].studentID = stdIDInput;
                    cout << "Please input the new student's name.\n";
                    getline (cin, newStdName);
                    stdRec[last].studentName = newStdName;
                    do
                    {
                        cout << "\n\nPlease input the new student's course code (the SCM offers courses 3506, 3633, 3634 \nand 3639).\n";
                        cin >> newStdCourseCode;
                        
                        if ((newStdCourseCode == 3506) || (newStdCourseCode == 3633) || (newStdCourseCode == 3634) || (newStdCourseCode == 3639)) 
                        {
                            stdRec[last].courseCode = newStdCourseCode;
                        }
                        else
                        {
                            cout << "Not a valid course code. SCM only offers courses 3506, 3633, 3634 or 3639.\n"
                                 << "Would you like to try again? Y/N";
                            cin >> optAgain6;
                            if(optAgain6 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain6 = 'Y');
                    
                    do
                    {
                        cout << "Please input the new student's credit points. Valid credit points can range from 0-240 as multiples of 10.\n";
                        cin >> newStdCreditPoint;
                        if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))
                        {
                            stdRec[last].creditPoint = newStdCreditPoint;
                        }
                        else
                        {
                            cout << "Not a valid credit point. Valid credit points can range from 0-240 as multiples of 10.\n"
                                 << "Would you like to try again? Y/N\n";
                            cin >> optAgain10;
                            if (optAgain10 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain10 = 'Y');
                    
                    cout << "The new student has now been added to the record as below.\n";
                    cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
                    cout << setiosflags(ios::left);
                    cout << setw(12) << stdRec[last].studentID
                         << setw(21) << stdRec[last].studentName
                         << setw(13) << stdRec[last].courseCode
                         << setw(5)  << stdRec[last].creditPoint << endl;
            }
            if((stdIDInput > "15000000") && (stdIDInput < "16666666"))
            {
                stdRec[last+1].studentID = stdRec[last].studentID;
                stdRec[last+1].studentName = stdRec[last].studentName;
                stdRec[last+1].courseCode = stdRec[last].courseCode;
                stdRec[last+1].creditPoint = stdRec[last].creditPoint;
                stdRec[last].studentID = stdRec[last-1].studentID;
                stdRec[last].studentName = stdRec[last-1].studentName;
                stdRec[last].courseCode = stdRec[last-1].courseCode;
                stdRec[last].creditPoint = stdRec[last-1].creditPoint;
                stdRec[last-1].studentID = stdIDInput;
                cout << "Please input the new student's name.\n";
                getline (cin, newStdName);
                stdRec[last-1].studentName = newStdName;
                do
                    {
                        cout << "\n\nPlease input the new student's course code (the SCM offers courses 3506, 3633, 3634 \nand 3639).\n";
                        cin >> newStdCourseCode;
                        
                        if ((newStdCourseCode == 3506) || (newStdCourseCode == 3633) || (newStdCourseCode == 3634) || (newStdCourseCode == 3639)) 
                        {
                            stdRec[last-1].courseCode = newStdCourseCode;
                        }
                        else
                        {
                            cout << "Not a valid course code. SCM only offers courses 3506, 3633, 3634 or 3639.\n"
                                 << "Would you like to try again? Y/N";
                            cin >> optAgain7;
                            if(optAgain7 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain7 = 'Y');
                
                do
                    {
                        cout << "Please input the new student's credit points. Valid credit points can range from 0-240 as multiples of 10.\n";
                        cin >> newStdCreditPoint;
                        if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))
                        {
                            stdRec[last-1].creditPoint = newStdCreditPoint;
                        }
                        else
                        {
                            cout << "Not a valid credit point. Valid credit points can range from 0-240 as multiples of 10.\n"
                                 << "Would you like to try again? Y/N\n";
                            cin >> optAgain11;
                            if (optAgain11 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain11 = 'Y');
                
                cout << "The new student has now been added to the record as below.\n";
                cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
                cout << setiosflags(ios::left);
                cout << setw(12) << stdRec[last-1].studentID
                     << setw(21) << stdRec[last-1].studentName
                     << setw(13) << stdRec[last-1].courseCode
                     << setw(5)  << stdRec[last-1].creditPoint << endl;
            }
            if((stdIDInput > "0") && (stdIDInput < "15000000"))
            {
                stdRec[last+1].studentID = stdRec[last].studentID;
                stdRec[last+1].studentName = stdRec[last].studentName;
                stdRec[last+1].courseCode = stdRec[last].courseCode;
                stdRec[last+1].creditPoint = stdRec[last].creditPoint;
                stdRec[last].studentID = stdRec[last-1].studentID;
                stdRec[last].studentName = stdRec[last-1].studentName;
                stdRec[last].courseCode = stdRec[last-1].courseCode;
                stdRec[last].creditPoint = stdRec[last-1].creditPoint;
                stdRec[last-1].studentID = stdRec[last-2].studentID;
                stdRec[last-1].studentName = stdRec[last-2].studentName;
                stdRec[last-1].courseCode = stdRec[last-2].courseCode;
                stdRec[last-1].creditPoint = stdRec[last-2].creditPoint;
                stdRec[last-2].studentID = stdIDInput;
                cout << "Please input the new student's name.\n";
                getline (cin, newStdName);
                stdRec[last-2].studentName = newStdName;
                do
                    {
                        cout << "\n\nPlease input the new student's course code (the SCM offers courses 3506, 3633, 3634 \nand 3639).\n";
                        cin >> newStdCourseCode;
                        
                        if ((newStdCourseCode == 3506) || (newStdCourseCode == 3633) || (newStdCourseCode == 3634) || (newStdCourseCode == 3639)) 
                        {
                            stdRec[last-2].courseCode = newStdCourseCode;
                        }
                        else
                        {
                            cout << "Not a valid course code. SCM only offers courses 3506, 3633, 3634 or 3639.\n"
                                 << "Would you like to try again? Y/N";
                            cin >> optAgain8;
                            if(optAgain8 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain8 = 'Y');
                
                do
                    {
                        cout << "Please input the new student's credit points. Valid credit points can range from 0-240 as multiples of 10.\n";
                        cin >> newStdCreditPoint;
                        if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))
                        {
                            stdRec[last-2].creditPoint = newStdCreditPoint;
                        }
                        else
                        {
                            cout << "Not a valid credit point. Valid credit points can range from 0-240 as multiples of 10.\n"
                                 << "Would you like to try again? Y/N\n";
                            cin >> optAgain12;
                            if (optAgain12 == 'N')
                            {
                                break;
                            }
                        }
                    }while (optAgain12 = 'Y');
                
            }
            else
            {
                cout << "Not a valid student ID. It cannot be less than zero and more than eight digits long.\n";
            }
        }
    }
        cout << "Would you like to search and/or add another student record? Y/N\n";
        cin >> option2;
        if(option2 == 'N')
        {
            break;
        }
        }while (option2 == 'Y');
        
        pause ();
        break;
    }

And and all direction would be awesome! Please and thanks!

From what I can see it does not appear as if you have allocated any extra space in your array, so at line 48 when you access stdRec[last+1] you are indexing an array out of bounds.

From what I can see it does not appear as if you have allocated any extra space in your array, so at line 48 when you access stdRec[last+1] you are indexing an array out of bounds.

Ohhh, so how do you think I could fix that?

This is what we're discussing towards the end of your other thread. You need to keep track of how big your array is (how many student-records you could have) and how much is used (how many student-records you actually have), and then don't try to look at a student-record that couldn't possibly exist because it would be past the end of your array.

This is what we're discussing towards the end of your other thread. You need to keep track of how big your array is (how many student-records you could have) and how much is used (how many student-records you actually have), and then don't try to look at a student-record that couldn't possibly exist because it would be past the end of your array.

Erm, well I have the maximum possible amount of student records set to 500 (which is MAXRECS) and I have the current amount of records set to 3 because of the information already in the array (which is NUMRECS). Now, I tried making NUMRECS just an int type and not constant because I thought that that way I'd be able to increment and decrement the amount of records I actually had... and I suddenly got errors! So I thought I couldn't do that... but with your other example in the other thread, you've got MAXRECS and NUMRECS as just int type and not constants... I am kind of confused now because when I did that I got errors...

Are you forced to use an array? This would all be much easier if you used a proper C++ container type such as vector.

Are you forced to use an array? This would all be much easier if you used a proper C++ container type such as vector.

Well we can either use an array of structs or paralleled arrays- and I've already coded my assignment with an array of structs... someone's given me advice to not set NUMRECS as a const int and I switched some things around and it was all fine :)

By the by, how about instead of this

if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))

you try something like

if ( (newStdCreditPoint >= 0)   &&  // greater than or equal to 0
     (newStdCreditPoint <= 240) &&  // greater than or equal to 240
     (newStdCreditPoint % 10) == 0 )  // a multiple of 10

By the by, how about instead of this

if ((newStdCreditPoint == 0) || (newStdCreditPoint == 10) || (newStdCreditPoint == 20) || (newStdCreditPoint == 30) || (newStdCreditPoint == 40) || (newStdCreditPoint == 50) || (newStdCreditPoint == 60) || (newStdCreditPoint == 70) || (newStdCreditPoint == 80) || (newStdCreditPoint == 90) || (newStdCreditPoint == 100) || (newStdCreditPoint == 110) || (newStdCreditPoint == 120) || (newStdCreditPoint == 130) || (newStdCreditPoint == 140) || (newStdCreditPoint == 150) || (newStdCreditPoint == 160) || (newStdCreditPoint == 170) || (newStdCreditPoint == 180) || (newStdCreditPoint == 190) || (newStdCreditPoint == 200) || (newStdCreditPoint == 210) || (newStdCreditPoint == 220) || (newStdCreditPoint == 230) || (newStdCreditPoint == 240))

you try something like

if ( (newStdCreditPoint >= 0)   &&  // greater than or equal to 0
     (newStdCreditPoint <= 240) &&  // greater than or equal to 240
     (newStdCreditPoint % 10) == 0 )  // a multiple of 10

Ah... yes, thanks! It's so much more succinct that way! Now everything is fine except one last thing: case 6 - adding a student record. Someone suggested I do something like:

const int MAXRECS = 20;  // or however many you need
StudentRecord StdRec[MAXRECS];  // all empty at this point
int NUMRECS = 0;  // there are no filled records in the array

...

// user wants to add a record
if (NUMRECS == MAXRECS) {
    cout << "Sorry, there's no more room to add a new student record" << endl;
}
else {
    // find insertIndex where to add a new record so that the array stays sorted:
    // such that stdRec[insertIndex-1].studentID < stdIDInput < stdRec[insertIndex].studentID
    // move records with (ID > newID) up one position -- opposite of when you delete
    for (int i = NUMRECS-1;  i >= insertIndex;  i--)
        stdRec[i+1] = stdRec[i];
    // copy data into freed-up record
    stdRec[insertIndex].studentID = stdIDInput;
    ...
    // update current number of used records
    NUMRECS += 1;
}

Note: not my code, found here: http://www.daniweb.com/software-development/cpp/threads/390141/page2

But the only thing is this: how do I find insertIndex? Can I use comparative operations like < and > like in my original code? Like if I said:

if(stdIDInput >=0 && < stdIDInput < 15000000)
{
     indertIndex = 1 // or something like that?
}

Any suggestions?

What I meant, and what I happen to think is easier is using a dynamic array. EG:

int *myarray=NULL;
int arraylength=0;
void AddInt(int *array, int &arraylen, int toadd)
{
    if (arraylength<=0)//initialize
        {myarray=new int;*myarray=toadd;return;}//copy toadd to the array
    int *temparray=new int[arraylen+1];//make room in RAM for an extra int
    for (int i=0; i<arraylen; i++)
        {temparray[i]=array[i];}
    temparray[arraylen++]=toadd;//add the value and increment the array length
    delete [] array;//remove the old array
    array=temparray;
}

Of course you would have to modify it to work for your particular situation.

What I meant, and what I happen to think is easier is using a dynamic array. EG:

int *myarray=NULL;
int arraylength=0;
void AddInt(int *array, int &arraylen, int toadd)
{
    if (arraylength<=0)//initialize
        {myarray=new int;*myarray=toadd;return;}//copy toadd to the array
    int *temparray=new int[arraylen+1];//make room in RAM for an extra int
    for (int i=0; i<arraylen; i++)
        {temparray[i]=array[i];}
    temparray[arraylen++]=toadd;//add the value and increment the array length
    delete [] array;//remove the old array
    array=temparray;
}

Of course you would have to modify it to work for your particular situation.

Ahaha, well I've changed my case 6 and made NUMRECS not a const to do so (changed a few more things around to fix the errors) and it *sort of* works... it's just when the user tries to input the new student's name, the prompt is there, but the part where the program waits for input is totally skipped over. I know cin doesn't take spaces as input, so I used getline(), but this problem is all I have left to contend with! Here's the relevant code:

case 6: // adding a student record
        {
        int first = 0;
        int last = NUMRECS-1;
        int mid;
        int newStdCourseCode, newStdCreditPoint, insertIndex;
        char decision3, option2, optAgaina, optAgainb;
        string newStdName;
        do
        {
        cout << "Please type in the student ID number\nof the student you want to input,\nthen press enter.\n";
        cin >> stdIDInput;
        bool found = false;
        while (first <= last && !found) // searches for a match
        {
            mid = (first + last)/2;
            if (stdRec[mid].studentID == stdIDInput)
            {
                found = true;
                cout << "This student ID already exists in the system.\n";
                cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
                cout << setiosflags(ios::left);
                cout << setw(12) << stdRec[mid].studentID
                     << setw(21) << stdRec[mid].studentName
                     << setw(13) << stdRec[mid].courseCode
                     << setw(5)  << stdRec[mid].creditPoint << endl;
            }
            else if (stdRec[mid].studentID > stdIDInput)
            {
                last = mid -1;
            }
            else
            {
                first = mid +1;
            }
        }
        if (!found)
        {
            cout << "Would you like to add the student to the records? Y/N\n";
            cin >> decision3;
            if(decision3 == 'Y')
            {
            
                insertIndex = 0;
                while (stdRec[insertIndex].studentID < stdIDInput)//finds where the input ID should go
                {
                    insertIndex++;
                }
                for (i = NUMRECS-1; i >= insertIndex; i--)//shuffles all the above IDs up one to make room
                {
                    stdRec[i+1] = stdRec[i];
                }
                stdRec[insertIndex].studentID = stdIDInput; // inserts new student info
                cout << "Please input the new student's name.\n";
                getline (cin,newStdName); // ***HERE! The program doesn't wait and skips over this part :(
                stdRec[insertIndex].studentName = newStdName;
                do
                {
                    cout << "Please input the new student's course code\n(the SCM offers courses 3506, 3633, 3634 and 3639).\n";
                    cin >> newStdCourseCode;
                    if ((newStdCourseCode == 3506) || (newStdCourseCode == 3633) || (newStdCourseCode == 3634) || (newStdCourseCode == 3639)) 
                    {
                        stdRec[insertIndex].courseCode = newStdCourseCode;
                    }
                    else
                    {
                        cout << "Not a valid course code. SCM only offers courses 3506, 3633, 3634 or 3639.\n"
                             << "Would you like to try again? Y/N";
                        cin >> optAgaina;
                        if(optAgaina == 'N')
                        {
                            break;
                        }
                    }
                }while (optAgaina = 'Y');
                do
                {
                    cout << "Please input the new student's credit points. Valid credit points can range from 0-240 as multiples of 10.\n";
                    cin >> newStdCreditPoint;
                    if ((newStdCreditPoint >= 0)  &&  (newStdCreditPoint <= 240)  &&  (newStdCreditPoint % 10 == 0))
                    {
                        stdRec[insertIndex].creditPoint = newStdCreditPoint;
                    }
                    else
                    {
                        cout << "Not a valid credit point. Valid credit points can range from 0-240 as multiples of 10.\n"
                             << "Would you like to try again? Y/N\n";
                        cin >> optAgainb;
                        if (optAgainb == 'N')
                        {
                            break;
                        }
                    }
                }while (optAgainb = 'Y');
            NUMRECS += 1;  
            }
        }
        cout << "The new student record has now been added as below:\n\n";
        cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
        cout << setiosflags(ios::left);
        cout << setw(12) << stdRec[insertIndex].studentID
             << setw(21) << stdRec[insertIndex].studentName
             << setw(13) << stdRec[insertIndex].courseCode
             << setw(5)  << stdRec[insertIndex].creditPoint << endl;
        cout << "\nWould you like to search and/or add another student record? Y/N\n";
        cin >> option2;
        if(option2 == 'N')
        {
            break;
        }
        }while (option2 == 'Y');
        
        pause ();
        break;
    }

Any suggestions would be greatly appreciated! Please and thank-you!

I'm not positive, but I think the problem is that

char val;
cin >> val;

doesn't do anything until you also hit enter/return (which puts an additional '\n' character on the stream). Then when you do

getline (cin,newStdName);

you actually get an empty line since the '\n' is still there. A quick solution would be to insert

cin.ignore(80, '\n');

before your call to getline ... this ignores up to 80 characters followed by the '\n' which you know is there. In fact, at this point, it might also work to type 'yes' instead of just 'y' at the previous prompt. Feel free to play around with it. There's a longer, detailed tutorial here, but don't worry yet if you don't follow everything in it ... the long and short of it is, unfortunately, that iostreams were so badly defined and implemented that it's a wonder we can use them at all. Well, maybe not -that- bad.... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.