So, I am trying to do this code, which lets the user know whether a given nr. is a perfect one or not. But I am facing some difficulties in a part of my code. I also tried to solve it with a debugger, and I always see the initial value of variable "i", which I use in my for-loop, take a huge random value for no reason at all. While for the nr. 6, you get the correct answer, for nr. 28 you don't.
And maybe this is the reason why my code doesn't work as it should
#include <iostream>
using namespace std;
int main()
{
int a,a_half,sum_divisor=0;
float multi=0.0;
cout <<"Give number: ";
cin >>a;
a_half = a/2;
for(int i = 1;i<=a_half;i++)
{
multi=a/i;
if(int(multi)==multi)
{
sum_divisor+=i;
}
}
if(sum_divisor==a)
{
cout << a<<" is a perfect one!"<<endl;
}else
{
cout <<a<<" is not a perfect number";
}
return 0;
}