0

C++ task about perfect number

The task Creat a program that imports 10 natural numbers from the keyboard and determines only the sum of the perfect numbers #include <iostream> using namespace std; int main() { int number, counter=1, sum=0, y=0, temp; for (int i=0; i<10; i++) cin>>number; // it is for importing 10 numbers temp=number; if(number<=0){ cout<<"error"; return 0; } while (counter<temp){ // if you want know if((temp%counter)==0) // your number is sum+=counter; // perfect or not you must counter++; // divide it all the numbers that } // smaller than it if (number==sum){ y=y+number; } else { break; } } cout<<y; return 0; } The problem is that I don't know where is my mistake

15th Jan 2019, 2:15 PM
Arsen
11 odpowiedzi
+ 1
Mina kapa dole
15th Jan 2019, 6:47 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
+ 1
Thanks Mina for helping
15th Jan 2019, 6:53 PM
Arsen
0
wait, what is the perfect number? also, please use code feature so it will be easier for us to fix the problem
15th Jan 2019, 5:38 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
For example 6 it have 4 divisors 1, 2, 3, and 6 If the sum of all divisors(of course except 6) is equal our number 6 it calls perfect number Perfect numbers are 6, 28, 496, 8128 after that the numbers are too high For example 28 . It divisors are 1, 2, 4, 7, 14; 1+2+4+7+14=28 It means that 28 is a perfect number
15th Jan 2019, 5:49 PM
Arsen
15th Jan 2019, 6:12 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
Edin no it is not right code . I think that it will be easier if you do it without arrays
15th Jan 2019, 6:17 PM
Arsen
0
And your code brings error
15th Jan 2019, 6:17 PM
Arsen
0
will try to find a solution tonight.
15th Jan 2019, 6:24 PM
Edin Hajdarevic
Edin Hajdarevic - avatar
0
Thanks Edin
15th Jan 2019, 6:29 PM
Arsen
0
Mina user has to input number
15th Jan 2019, 6:29 PM
Edin Hajdarevic
Edin Hajdarevic - avatar