All pastes #2085985 Raw Edit

Unnamed

public text v1 · immutable
#2085985 ·published 2011-10-01 00:45 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";
    
    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";
            
            
         }
       else if (inputreturn==false)
         {
            cout << input << " is not prime! It is divisible by: " << divisor << "\n";
         }        
    }
    
    cout << "Thanks for playing!\n";
    system("pause");
}