0
// Ashton Pearson, 558771747
//
// This program reads an integer and determines whether
// or not it is a perfect integer.

#include <iostream>
using namespace std;

int main()
{
    int x;
    int iCount = 1;
    int sum = 0;

    cout << "Enter an integer to test (< 2 to exit): ";
    cin >> x;


    while (x >= 2 )
    {
        cout << "Testing " << x << "..." << endl;

        while (iCount <= (x/2))
        {
            if (x % iCount == 0)
            {
                sum = sum + iCount;
                iCount = iCount + 1;
            }
            else 
            {
                iCount = iCount + 1;
            }
        }
        if (x == sum)
        {
            cout << x << " is perfect\n";
        }
        else
        {
            cout << x << " is NOT perfect\n";
        }
            cout << "\nEnter an integer to test (< 2 to exit): ";
            cin >> x;
    }

    return 0;
}

Everything works fine. 6 says perfect (which is good), BUT it says 28 is NOT a perfect number but it is!!! help plz!!

Edited by mike_2000_17: Fixed formatting

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ashtonpearson
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.