All pastes #2086110 Raw Edit

Something

public text v1 · immutable
#2086110 ·published 2011-10-01 18:21 UTC
rendered paste body
#include <iostream>
using namespace std;

/* Function named isitprime that does the logic in determining prime
   it returns a true / false for whether or not it is prime.  It also
   assigns the divisor value to the variable divisor from the main 
   body of the program.  */
   
bool isitprime (int testinput, int &testdivisor)
{
    bool primebool;
    for (testdivisor=2; testinput>=testdivisor ;testdivisor++)
    {        
        if (testinput == testdivisor)
        {
            primebool=true;
            break;
        }
        else if ((testinput%testdivisor) == 0)
        { 
            primebool=false;
            break;
        }      
    }
return (primebool);
}



/* Main body of thr prime program.  Has a few checks for valid entry from
   the user.  */
   
int main()
{
    int input, divisor;
    bool inputreturn;
    cout << "Welcome to the Prime Program!\n";
    input=10000;
    for (divisor=2; divisor<input; )
    {
       cout<<"Please enter an integer value greater than 2! (0 to quit):  ";
       cin>>input;
       if (input==0)
            break;
       if (input<=1)
            {
                cout << input << " is not a valid entry!!!  Try again!\n\n";
                input=10000;
                continue;
            }
       if (input==2)
            {
                cout << input << " is the only even integer that is prime!\n\n";
                input=10000;
                continue;
            }     
       inputreturn=isitprime(input, divisor);
       if (inputreturn==true)
         {
            cout<<input<<" is prime!\n";
            divisor=2;            
         }
       else if (inputreturn==false)
         {
            cout << input << " is not prime! It is divisible by: " << divisor << "\n\n";
            divisor=2;
         }        
    }
    
    cout << "Thanks for playing!\n";
    system("pause");
}