Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i want to change my variable passed as argument to this function:

bool verifyStudent(string id, string name, int grade, int points, string type) {
if(!verifyId(id)){
    cerr << "Please enter 8 charactes id! format: YYMMDDCC
";
    cin >> id;
    return false;
} else
if(!verifyName(name)){
    cerr << "Please enter name to 35 characters!
";
    cin >> name;
    return false;
} else
if(!verifyGrade(grade)){
    cerr << "Please enter class between 8 and 12!
";
    cin >> grade;
    return false;
} else
if(!verifyPoints(points)){
    cerr << "Please enter points between 0 and 300!
";
    cin >> points;
    return false;
} else
if(!verifyType(type)){
    cerr << "Please enter 1 charater type! format: R,r - regional, D,d - district, N,n - national, I,i - international
";
    cin >> type;
    return false;
} else {
    return true;
}

}

how i should get access to the given variable and change it when it isn't verified by other function?

here is the way i call the function:

verifyStudent(iId, iName, iGrade, iPoints, iType);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
98 views
Welcome To Ask or Share your Answers For Others

1 Answer

In order to change the arguments, you would have to take references:

bool verifyStudent(string& id, string& name, int& grade, int& points, string& type) 

Although I'd say that function is not verifyStudent as much as verifyAndCorrectStudentIfNeeded.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...