i am writing a program that calculates the sum of three numbers. i understand that part. however i must validate my code in such a way that i could only enter an integer not a character. i heard there is a function that i could use. i would greatly appreciate some form of help.
int i;
cout << "What is the score of the student? "; //Get score
//Ensure that score is actually an integer
while (!(cin >> i))
{
cin.clear();
cin.ignore(1000,'\n');
//If not an integer, repeat until so
cout << "What is the score of the student (integer value's only): ";
}
score[pk] = i; //If so.. Put score in here
This is off a program I wrote the full source is here if this doesn't help..
All it does is say while cin is not going into i (because its an integer)... do SOMETHING until cin can put information into ... When finally true.. then (i was workin on something) score[pk] will equal i..