Hello all,
I had previously written a short program to find the factors of any integer. Fortunately, it works flawless and without any problems. However, I want to edit this code so that the program adds up all the factors of that certain integer. Can anyone shed some light as to how to do this?
The code I have is the following
#include <iostream>
using namespace std;
main()
{
int a;
int b;
b = 0;
cout<<"Enter a number:";
cin>>a;
for (b=2; b<=a; b++)
{
if (a % b == 0)
cout << b << " is a factor of " << a << endl;
}
return 0;
}
I tried stating that
sum = 1
and that sum= sum + b + a / b
But it didn't work.
Help would very much be appreciated.