Large #s and using "isalpha" causes pgm to loop

Entering large #'s and non-numeric causes the program to loop. Any advice??

#include <iostream>
#include <cstdlib>
#include <exception>
#include <cmath>
#include <cctype>
using namespace std;

void primeFactor(long wholeNumber);

int main(void)
{
int whole = 0;
char again = 'N';

do
{
system("cls");
do
{
cout << "Please enter a Whole number greater than 1: ";
cin >> whole;
cin.get();
if(whole < 1 || isalpha) // cannot be negative number not defined
cerr << "***Whole number cannot < 1!***" << endl;
}while(whole <1 || isalpha);

try
{
cout << whole << " = " << " ";
primeFactor (whole);
}
catch(exception e)
{
cout << "Exception:" << e.what() << endl;
cout <<"Press the \"Enter\" key to continue";
cin.get();
}
cout << "Continue? (Y/N): ";
cin.get(again);
if(again == '\n')
again = 'Y';
else
cin.ignore(255,'\n'); // read past CR
putchar('\n');
}
while(again == 'Y' || again == 'y');

puts("Press the \"Enter\" key to continue");
cin.get(); // hold window open
return EXIT_SUCCESS;

}
//-----------------------------------------------------------------------
//------------------------------------------------------------------------------
void primeFactor(long wholeNumber)
{
int i=2;
static int count = 0;

if(wholeNumber!=2)
{
do
{
if(wholeNumber%i==0) // if it is divisible it is not prime
{
cout << "(" << i << ")";
count++;
primeFactor(wholeNumber/i);
return;
}
i++;
}
while(i <= sqrt((long double)wholeNumber));
}

if(count ==0)
{
cout << "(" << wholeNumber << ")" << " " << ":Prime!" << endl;
}
else
{
cout << "(" << wholeNumber << ")" << " " << endl;
count=0;
}
}
You need to pass an argument to isalpha.

http://cplusplus.com/reference/clibrary/cctype/isalpha.html
Topic archived. No new replies allowed.