All pastes #2086022 Raw Edit

Untitled

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

bool isitprime (int testinput, int &testdivisor)
{
    
//    cout << "\n\n test input: " << testinput << "\n";
//    cout << "test divisor: " << testdivisor << "\n";
    bool primebool;
//    int num;
    
    
    for (testdivisor=2; testinput>=testdivisor ;testdivisor++)
    {
//        cout << "\ntest input: " << testinput << "\n";
//        cout << "test divisor: " << testdivisor << "\n";
//        cout << "primebool: " << primebool << "\n";  
        
        if (testinput == testdivisor)
        {
            primebool=true;
//            cout<<primebool;
            break;
        }
        else if ((testinput%testdivisor) == 0)
        {
            
            primebool=false;
//            cout<<primebool;
            break;
        }

        
    }
//cout << "\n" << primebool << "\n";
return (primebool);
}


int main()
{
    int input, divisor;
    bool inputreturn;
    cout << "Welcome to the Prime Program!\n";
    input=100;
    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==2)
            {
                cout << input << " is the only even integer that is prime!\n";
                input=input+100;
                continue;
            }     
       inputreturn=isitprime(input, divisor);
//       cout << inputreturn << "\n";
       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";
            divisor=2;
         }        
    }
    
    cout << "Thanks for playing!\n";
    system("pause");
}