Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:07+00:00 2026-06-13T02:51:07+00:00

What I am trying to do is search for a perfect number. A perfect

  • 0

What I am trying to do is search for a perfect number.
A perfect number is a number that is the sum of all its divisors, such as 6 = 1+2+3.

Basically what I do here is ask for 2 numbers and find a perfect number between those two numbers. I have a function that tests for divisibility and 2 nested loops.

My issue is that I don’t get any result. I’ve revised it & can’t seem to find anything wrong. The compiler doesn’t shoot out any errors.

What can be wrong?

#include <iostream>
using namespace std;

bool isAFactor(int, int);

int main()
{

int startval;
int endval;
int outer_loop;
int inner_loop;
int perfect_number = 0;

cout << "Enter Starting Number: ";
cin >> startval;
cout << "Enter Ending Number: ";
cin >> endval;

for(outer_loop = startval; outer_loop <= endval; outer_loop++)
{
    for(inner_loop = 1; inner_loop <= outer_loop; inner_loop++)
    {
        if (isAFactor(outer_loop, inner_loop) == true)
        {
            inner_loop += perfect_number;
        }
    }

if (perfect_number == outer_loop)
{
    cout << perfect_number << " is a perfect number." << endl;
}

else
{
    cout << "There is no perfect number." << endl;
}

}

system("PAUSE");
return 0;
}

bool isAFactor(int outer, int inner)
{
if (outer % inner == 0)
{
    return true;
}

else
{
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:51:08+00:00Added an answer on June 13, 2026 at 2:51 am

    inner_loop += perfect_number; should be perfect_number += inner_loop;.

    There are other issues — you need to reset perfect_number to zero in each outer loop, and you should presumably print the message "There is no perfect number." if none of the numbers in range is perfect, rather than printing it once for every number in range that is not perfect.

    I’d advise that you rename perfect_number to sum_of_factors, outer_loop to candidate_perfect_number and inner_loop to candidate_factor, or similar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to search through many documents and find all instances where an html
So I'm trying to search through a model through a form. Basically my end
I am trying to search a char* to find matches and store each match
I am trying to search the C:\ drive for all files with a certain
I'm trying to search Google but the keyword 'go' makes it difficult to find
I am trying to search the AddressBook for Phone Numbers by name, -(void)textMessage{ ABAddressBookRef
Im trying to search through a text file and find the valid email addresses.
I am trying to search through the .htm files for our intranet to find
I am trying to search my database to see if a number exists in
I am trying to search and replace special characters in strings that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.