This code is supposed to find all of the perfect numbers up to 100,000. I can get it to compile but I can't get anyhting to print to the screen.
#include <iostream>
#include "math.h"
using namespace std;
int main()
{
unsigned int n = 100000,sum = 0, num = 0, value = 0;
for(int num; num <= n; num++)
{
sum = 0;
for(int i = 1; i <= (num/2); i++)
{
if(num%i == 0) //True is i is a factor of num
{
sum+=i;
}
}
First: please put the code in code tags, it makes it much more readable.
Your issue is that all of the couts are inside your if statement, which never gets executed. sum will never equal num because sum is repeatedly set to 0 at the beginning of your first for-loop.