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

Here's the code that I have:


//---------------------------------------------------------------------------------
// Functions: main()
//
// File: Prime.cpp
//
// Title: Prime Factorization
//
// Description: This file contains funtion main () which will calculate the
// prime factors of positive whole numbers.
//
// Programmer: Joanne Pietryga
//
// Date: 02/13/2008
//
// Version: 1.01
//
// Environment: Hardware:IBM Pentium+
// Software: Windows XP or 98+ with .NET framework for
// execution;
// Compiles under Microsoft Visual C++ 2003
//
// Input: int whole (the whole number in which to find the prime factors for)
//
// Output: prompts, display of prime factors to console
//
// Calls: primeFactor()
// Called By: n/a
// Parameters: void
//
// Returns: int EXIT_SUCCESS = successful
//
// History Log:
//
//
//
//------------------------------------------------------------------------------
#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;
}
}
Topic archived. No new replies allowed.