Q:

Simple code is displaying absurdly large numbers...?

I have run this program before and it worked fine.  Then I added the "if" statements to the "set" methods and i started seeing very large numbers when I ran the program.  What can I do to fix this problem or can someone enlighten me as to why this is happening?   
class GradeBook{

public: 
    void setStudentID(int ID){

        if(10000 <= studentID && studentID <= 50000){

            studentID = ID;
        }
    }

    int getStudentID(){

        return studentID;
    }

    void setStudentGrade(int grade){

        if(0 <= studentGrade && studentGrade <= 100){

        studentGrade = grade;
        }
    }

    int getStudentGrade(){

        return studentGrade;
    }

    void displayMessage(){

        cout << "Student " << getStudentID() << " has a score of " << getStudentGrade() << endl;
    }

private:

    int studentGrade;
    int studentID;
};

int main(){

    int nameOfID;
    int nameOfGrade;
    GradeBook gb;

    cout << "Please enter a student ID: " << endl;
    cin >> nameOfID;
    gb.setStudentID(nameOfID);
    cout << "Please enter the student's grade: " << endl;
    cin >> nameOfGrade;
    gb.setStudentGrade(nameOfGrade);
    getchar();

    gb.displayMessage();
    getchar();
}

A:

You have your comparisons wrong you meant.
if(10000 >= studentID && studentID <= 50000)

You don't have else statements to make sure the variable is initialized, thus I'd change it to:
if(10000 >= studentID && studentID <= 50000){
     studentID = ID;
}
else{
     studentID = 0; //or whatever value you want to mean invalid
}

That will hopefully fix your issues.

