Part of the code from the program I'm having trouble with. The deletion of array element for this doesn't work properly. Can anyone tell me why? I can't spot any mistakes though zzz,

cin.ignore();
delStudentCounter = 0;
cout << "Please enter ID to delete student: ";
cin.getline(delStudent, 50);
for (int n = 0; n < MAX_STUDENTS; n++)
{
    if (strcmp(delStudent, students[n].ID) == 0)
    {
        delStudentCounter = 1;    
        delStudentNumber = n;
    }
}
if (delStudentCounter = 1)
{
    for (int o = delStudentNumber; o < MAX_STUDENTS-1; o++)
    {
        students[o] = students[o+1];
    }
    i--; 
}
else
    cout << "Student does not exist!";

Recommended Answers

All 5 Replies

I see an = where there should be an ==

What compiler, and what warning level are you at?

Your post is equivalent to the following:

My toe hurts. Can you tell me why?

Please tell us what is happening that you don't expect to happen. Otherwise your guess as to why my toe hurts will only be as good as my guess as to why you aren't getting the desired results.

I'm really sorry about the vague explanation! Was panicking since the assignment's due real soon.

Salem thanks! Didn't spot the ==, sneaky little =. I'm using Dev c++. Should I get another?
Seems to work fine after I added the =. However, I'm having a gut feeling that something's still wrong... Hmm.

The problem I had before:
There's 1, 2, 3, 4, 5 and 6 in the array.
I deleted 1. Works fine. 2 3 4 5 6 is left.
Tried deleting 1 again, which shouldn't happen but happens anyway and 2 is deleted. 3 4 5 6 is left.
Tried deleting 2 which works? and 3 is deleted. 4 5 6 is left.

It appears as if you might find already deleted students, because of the ...

for (int n = 0; n < MAX_STUDENTS; n++)
{
    if (strcmp(delStudent, students[n].ID) == 0)
    {
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.