// Just showing how to do slow prime calculating. // You may do whatever you want with this. // Calmatory 2008 #include #include #include "prime.h" #include // for GetTickCount(). using namespace std; // init vars. int i=0; int primes=0; int start=0, end=0; int numprimes=0; char sel; int main(int argc, char *argv[]) { CPrime prime; STimer timer; start: cout << "###################################" << endl; cout << "# SloPrime v1.0 #" << endl; cout << "# #" << endl; cout << "# a) Calculate 16384 primes #" << endl; cout << "# b) Calculate 32768 primes #" << endl; cout << "# c) Calculate 65535 primes #" << endl; cout << "# #" << endl; cout << "# q) Quit #" << endl; cout << "# #" << endl; cout << "###################################" << endl; cin.get(sel); // get user input // check user input and return if necessary. if(sel == 'a') { numprimes = 16384; } if(sel == 'b') { numprimes = 32768; } if(sel == 'c') { numprimes = 65535; } if(sel == 'q') { return 0; } if(sel != 'a' && sel != 'b' && sel != 'c' && sel != 'q') { goto start; } cout << "Starting to calculate first " << numprimes << " prime numbers!" << endl << "This may take a while . . ." << endl; // starting the timer. timer.start = GetTickCount(); while(primes<=numprimes) { i++; if(prime.GetPrime(i)==2) { primes++; }; // check if the value of i is a prime number. } timer.end = GetTickCount(); timer.elapsed = (timer.end-timer.start)/1000.0f; // Get time in seconds since we started the timer. printf ("Calculated %d primes in %.4f seconds!\n", primes-1, timer.elapsed); // the -1 is because of "primes<=numprimes" in the while loop. That is because of the fact that with < instead of <= // the program does not calculate the very last prime. This does not have anything to do with the actual result though! system("pause"); // I personally HATE this, but if we were using cin.get(), there would be some problems. Check yourself. }