Hi, I need to create a program that will display if a number is a perfect number or not. We need to use a boolean to determine if its perfect or not. Heere is what I have, but it's not working correctly.It displays that all numbers are perfect.Can someone help me find the problem?
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
//Prompt user to enter number and declare variables.
int n, sum = 0, f;
cout << "Please enter a number." << endl;
cin >> n;
while (n < 0)
{
cout << "Please enter a number." << endl;
cin >> n;
}
//Declare a boolean variable and additional variables as needed.Use rule to determine if it's a perfect number.
bool result;
for( f = 1; f <= n/2; f++)
if ( n % f == 0)
sum += f;
if ( sum == n)
result = true;
else
result = false;
//Use boolean variable to display results.
if (result = true)
cout << "The number " << n << " is a perfect number." << endl;
else if (result = false)
cout << "The number " << n << " is not a perfect number." << endl;