whenever I enter 0 in the string value to quit the loop it does not work
PLEASE HELP ME!!

#include<iostream>
#include<string>
#include<fstream>
#include<cctype>
#include<stdlib.h>
using namespace std;

struct Student
{
    string netID;
    string firstName;
    string lastName;
    int maxCourses;
    int numCoursesEnrolled;
};

const int SIZE = 100;

int readStudentData(string, Student *[], int);

void registration(Student *[], int);

bool validateString(const string &);

bool myStoi(const string & s, int & res);

//int searchStudent(const string & pluStr, Student *arrayStud[], int numStudents);

int main()
{
    Student *studptr[SIZE];
    //int index;

    string filename = "studentData0.txt";
    string filename1 = "studentData1.txt";
    string filename2 = "studentData2.txt";
    string filename3 = "studentData.txt";

    readStudentData(filename, studptr, SIZE);

    cout << endl;

    readStudentData(filename1, studptr, SIZE);

    cout << endl;

    readStudentData(filename2, studptr, SIZE);

    cout << endl;

    readStudentData(filename3, studptr, SIZE);

    cout << endl << endl;

    int choice;

    cout << "1 - Registration" << endl;
    cout << "2 - Close and exit" << endl;
    cin >> choice;

    while (choice != 2)
    {
        registration(studptr, SIZE);
    }

    return 0;
}

int readStudentData(string fName, Student * arrayStud[], int max_size)
{
    int count = 0;
    ifstream input;
    input.open(fName);

    if (!input)
    {
        cout << "file does not exists" << endl;
    }
    else
    {
        cout << "fname = " << fName << endl;
        cout << "---------------------" << endl;
        cout << endl;

        while (!input.eof())
        {
            arrayStud[count] = new Student;
            input >> arrayStud[count]->netID;
            if (!validateString(arrayStud[count]->netID))
            {
                cout << "Error reading file " << fName << endl;
                break;
            }
            else
            {
                input >> arrayStud[count]->firstName;
                input >> arrayStud[count]->lastName;
                input >> arrayStud[count]->maxCourses;
                input >> arrayStud[count]->numCoursesEnrolled;

                if (arrayStud[count]->maxCourses >= 0 && arrayStud[count]->numCoursesEnrolled >= 0)
                {
                    if (arrayStud[count]->maxCourses >= arrayStud[count]->numCoursesEnrolled)
                    {
                        cout << "net ID: " << arrayStud[count]->netID;
                        cout << ". First and the last name " << arrayStud[count]->firstName << " ";
                        cout << arrayStud[count]->lastName << endl;
                        cout << "max # of courses: " << arrayStud[count]->maxCourses;
                        cout << ". # of courses enrolled: " << arrayStud[count]->numCoursesEnrolled << endl;
                    }
                    else
                    {
                        cout << "Error reading file " << fName << endl;
                        break;
                    }

                }
                else
                {
                    cout << "Error reading file " << fName << endl;
                    break;
                }

                cout << endl;
            }

            /*
            cout << arrayStud[count]->netID << arrayStud[count]->firstName;
            cout << arrayStud[count]->lastName << arrayStud[count]->maxCourses;
            cout << arrayStud[count]->numCoursesEnrolled << endl;
            */

            count++;
        }

        input.close();
    }

    return count;
}

void registration(Student *arrayStud[], int nStud)
{
    int counter;
    bool done = false;

    while (!done)
    {

        string id = "";
        int convertString = 0;
        cout << "enter id: ";
        cin >> id;

        while (!validateString(id))
        {
            cout << "Incorrect netID format. netID must have only letters or digits, reenter: ";
            cin >> id;
        }

        if (myStoi(id, convertString))
        {
            if (convertString == 0)
            {
                //cout << "notworking" << endl;
                done = true;
            }
        }
    }

}

bool validateString(const string &s)
{
    int length = 0;

    length = s.length();

    //cout << length << endl;

    for (int i = 0; i < length; i++)
    {
        if (!isalnum(s.at(i)))
        {
            return false;
        }

    }

    return true;
}

bool myStoi(const string & s, int & res)
{
    bool convert = true;

    int length = s.length();

    if (length == 0)
    {
        convert = false;
    }
    for (int k = 0; k < length; k++)
    {
        if (!(isdigit(s[k])))
        {
            convert = false;
        }
    }

    if (convert)
    {
        res = stoi(s);
    }
    return convert;
}

You need to redo lines 59-65 - the input is only taken once. It then becomes an endless loop unless you input 2 in the first place.

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.