Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having a minor problem with my program. I want my program to output when th

ID: 3625568 • Letter: I

Question

I'm having a minor problem with my program. I want my program to output when the number isn't perfect as well. It already outputs when the number isn't prime, but I also want it to output when it's not perfect as well. Such as in the sample run indicated below:

Thank you


Sample Run

Enter integers between 1 and 1000: 16

16 is not prime

The divisors of 16 are:

1 2 4 8 16

16 is not perfect
Press any key to continue . . .




Here is my code:

#include <iostream>
using namespace std;
int main ()
{
int num, n, divisor;
int sum=0;
const int SENTINEL=-1;
bool Continue = false;
bool> do {
if (!Continue)
cout<<"Enter integers between 1 and 1000: ";
else
cout<<"Please re enter a number between 1 to 1000: ";
Continue = false;
cin>>num;
cout << endl;
if(0<num && num<=1000)
{
for ( n=2; n < num; n++ )
{
if ((num % n)==0 )
break;
}
if ( n==num )
{
cout << num <<" is prime "<< endl;
}
else
{
cout << num << " is not prime " << endl;
}
for(divisor=1; (divisor <= num/2); divisor++)
{
if (( num%divisor==0) && (num!=divisor))
{
if (!Once)
{
cout << "The divisors of " << num << " are: " << endl;
> }
else;
cout << divisor << " ";
sum +=divisor ;
}
else;

if(sum==num)
{
cout << num;
cout << " " << num << " is a perfect number " << endl;
}

}
if(sum!=num)
cout << num;
cout << endl;
}


else
{
cout<<"Invalid the number should be between 1 and 1000 " << endl;
Continue = true;
}
} while (Continue);
return 0;
}

Explanation / Answer

#include <iostream>
using namespace std;
int main ()
{
int num, n, divisor;
int sum=0;
const int SENTINEL=-1;
bool Continue = false;
bool> do {
if (!Continue)
cout<<"Enter integers between 1 and 1000: ";
else
cout<<"Please re enter a number between 1 to 1000: ";
Continue = false;
cin>>num;
cout << endl;
if(0<num && num<=1000)
{
for ( n=2; n < num; n++ )
{
if ((num % n)==0 )
break;
}
if ( n==num )
{
cout << num <<" is prime "<< endl;
}
else
{
cout << num << " is not prime " << endl;
}
for(divisor=1; (divisor <= num/2); divisor++)
{
if (( num%divisor==0) && (num!=divisor))
{
if (!Once)
{
cout << "The divisors of " << num << " are: " << endl;
> }
cout << divisor << " ";
sum +=divisor ;
}
if(sum==num)
{
cout << num;
cout << " " << num << " is a a perfect number " << endl;
}
}
}
if(sum!=num)
{
          
cout << " " << num << " is not a perfect number " << endl;
// cout << "besause sum of divisors " << sum << " not equal to " << num <<endl;
cout << endl;
}


else
{
cout<<"Invalid the number should be between 1 and 1000 " << endl;
Continue = true;
}
} while (Continue);
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote