//goldemerald's prime numbers program
//i do not know how to use binary or new line stuff :P
// Required if your program does any I/O
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
// Required for ANSI C++ 1998 standard.
using namespace std;
void decision();
void myNumber();
void morePrimeNumbers(int &count);
void reset(int &count);
int main()
{
cout << "goldemerald's prime number program" << endl;
decision();
system("pause");
return 0;
}
void decision()
{
char decide;
int count = 1;
cout << "What would you like to do: " << endl;
cout << "See if a number is a prime number, press 'A'; See if numbers are prime in a row, press 'B'; Reset seen prime numbers to 0, press 'C'; Or press 'Q' to quit: ";
cin >> decide;
while (decide != 'Q')
{
if (decide == 'A')
myNumber();
if (decide == 'B')
morePrimeNumbers(count);
if (decide == 'C')
reset(count);
cout << "See if a number is a prime number, press 'A'; See if numbers are prime in a row, press 'B'; Reset seen prime numbers to 0, press 'C'; Or press 'Q' to quit: ";
}
}
void myNumber()
{
int number;
int increase = 1;
double x;
string answer;
answer = "yes";
cout << "What is the number you want to check if it's a prime number?" << endl;
cin >> number;
while (increase < number)
{
//ensures that 1 is not used for number or increase
x = number/increase;
//sees if the number has a remainder, if no, the number is not prime
if ((number%increase) == 0 && x != 1 && x != number)
answer = "no";
//tells the user their number is not prime
if (answer == "no")
{
cout << answer << " it is not a prime number!" << endl;
return;
}
//increases the divisor by 1 to see if the next integer increased will have a remainder
increase++;
}
//if the number always has a remainder, it tells the user it's a prime number
cout << answer << " it is a factor!" << endl;
}
void morePrimeNumbers(int &count)
{
int x;
int y;
int increase = 1;
//j is a binary set to false, but i dont know how to use those :P
int j = 0;
int input;
cout << "How many (more) prime numbers would you like to see? ";
cin >> input;
//sets x to be the number of factors to be seen to the users input plus, starting from 1 or the last place left off
x=count + input;
cout << "Here are the next " << input << " prime numbers:" << endl;
//a loop to show the numbers from start to the input number
while (count < x)
{
//the increasing number that will be dividing the next number(count) to see if there is a remainder
while (increase < count && j != 1)
{
y = count/increase;
//if the number can be divided, it tells the user
if (count%increase == 0 && y != 1 && y != count)
{
cout << count << "is not a factor!" << endl;
//sets the binary number to true for later use
j = 1;
}
//increases the divisor to see if the next number up can divide it
increase++;
}
//resets the divisor
increase = 1;
//if the binary number is false, tell the user the number is a prime number
if (j==0)
cout << count << "is a factor!" << endl;
//resets the binary number to false
j=0;
//now we move up to the next number
count++;
}
}
void reset(int &count)
{
count = 1;
cout << "It has been reset to 1!" << endl;
}