void fDisplayExplanation(){
cout << "This program asks the user to enter a loop count,\n"
<< "reads the loop count to the user,\n"
<< "then reads the sum of the loop to the user.\n"
<< endl;
}
int fGetSum(){
int nCount;
do{
cout << "Please enter loop count: ";
cin >> nCount;
cout << endl;
if(nCount <= 0){
cout << "Please enter a positive integer." << endl;
cout << endl;
}
}
while(nCount <= 0);
int nSum = 0;
for(int i = 1; i <= nCount; i++){
nSum += i;
cout << "The loop count is " << i << "." << endl;
}
return nSum;
}
int main(int nNumberofArgs, char* pszArgs[]){
fDisplayExplanation();
int nLoopSum = fGetSum();
cout << endl;
cout << "The total sum of the loop is " << nLoopSum << ".\n" << endl;
system("PAUSE");
return 0;
}
I have the while loop programmed to loop if an integer below or equal to 0 is entered. I want it to loop if the value entered is anything other than an integer range above or equal to 1 (so alphanetical characters, symbols, etc). Might this be easy enough for me to code an grasp?
I am not sure if this is what you need, but there are some ANSI C functions in the header ctype.h (in C++ one needs to include cctype ), that might aid you please take a look at
I see that checks characters, is there something that checks integer input for an alphabetical character and then returns an error? Or better yet, checks for anything other than an integer and returns an error?