Code:
#include<iostream>
#include<conio.h>
void perfect(int); // function prototype
using std::cout;
using std::cin;
using std::endl;
int main()
{
int num; // declare varibale
cout<< "Enter an integer:\t"; // prompt the user for input
cin>> num; // read num
perfect(num);
getch();
}
// definition perfect()
void perfect(int userChoice)
{
int sum,rem;
for(int value=1;value<=userChoice;value++)
rem=userChoice/value;
sum+=value;
int result=1+sum;
if((userChoice/value)==0 && result=userChoice)
cout<< "perfect";
else
cout<< "not perfect";
}
4 erors in this program. It is supposed to tell wether a number is perfect number or not.
int sum,rem;
for(int value=1;value<=userChoice;value++)
rem=userChoice/value;
sum+=value;
int result=1+sum;
if((userChoice/value)==0 && result=userChoice)
cout<< "perfect";
else
cout<< "not perfect";
The user inputs 'userChoice'. userChoice is divided by the 'value'. After that it sums up all the value and if result is equal to the num it couts' perfect, yet some logical errors in the program.