Trying to output a list of all prime numbers and perfect numbers between 1 and 1000.
Have been banging head against wall for past 3 hours and this is what I have so far:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int x, aDiv, aMax, aPerfectNum;
bool aPrime, aPerfectNumBool;
int aCurrentNum;
aPerfectNum = 0;
aMax = 1000;
aPrime = false;
aPerfectNumBool = false;
for(aCurrentNum = 2; aCurrentNum < aMax; aCurrentNum++)
{
//Find Prime loop
for (x = 1; x < aCurrentNum; x++)
{
if (aCurrentNum % x != 0)
{
aPrime = true;
}
else
{
aPrime = false;
//Find Divisors Loop
for(aDiv = 1; aDiv <= aCurrentNum; aDiv++)
{
//Found Divisor
if (aCurrentNum % aDiv == 0)
{
//Add for Perfect Number
if (aDiv != aCurrentNum)
{
aPerfectNum += aDiv;
}
}
}
if (aPerfectNum == aCurrentNum)
{
aPerfectNumBool = true;
}
}
}
//Output
if (aPrime == true)
{
cout << aCurrentNum << " is a prime number";
}
if (aPerfectNumBool == true)
{
cout<< aCurrentNum << " is a perfect number";
}
}
system ("pause");
}
I tired to use break;
in the "else" statement under the find prime loop, but that just seems to end the entire looping process from the first "for" loop
Any suggestions on how to make it function properly?