0

the programe output the sum of the factor of a number
entered by user and when he enter 0 the programe should display output with no result for 0
here is the code

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int x,i;
    int z=1;
    int sum=0;

        while(cin>>x)
        {
            if(x!=0)
            {
        for(int i=1;i<x;i++)
        {
            if(x%i==0)
            {
                z=i;
            }
            if(x%i!=0)
            {
                continue;
            }
            sum+=z;
        }
            }
            if(x==0)
            {
                break;
            }
        }
cout<<"PERFECTION"<<" "<<"OUTPUT"<<endl;
if(sum==x)
{
    cout<<setw(5)<<x<<"  "<<"PERFECT"<<endl;
}
else if(sum>x)
{
    cout<<setw(5)<<x<<"  "<<"DEFICIENT"<<endl;
}
else if(sum<x)
{
    cout<<setw(5)<<x<<"  "<<"ABUNDANT"<<endl;
}
cout<<"END OF OUTPUT"<<endl;

return 0;

}

Edited by Nick Evan: Fixed formatting

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Freaky_Chris
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.