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

Write a C++ program that prompts the user to enter an integer greater than 1. Yo

ID: 3630009 • Letter: W

Question

Write a C++ program that prompts the user to enter an integer greater than
1. Your program should then compute the sum of all the proper factors of
the number and determine whether or not the number is a perfect number.
The input and output of your program MUST be formatted as shown below.
Name your source file isperfect.cpp.
Sample Run 1:
Enter an integer greater than 1> 0
The number that you enter must be greater than 1.
Sample Run 2:
Enter an integer greater than 1> 10
1 + 2 + 5 <> 10
10 is not a perfect number.
Sample Run 3:
Enter an integer greater than 1> 6
1 + 2 + 3 = 6
6 is a perfect number.
Sample Run 4:
Enter an integer greater than 1> 28
1 + 2 + 4 + 7 + 14 = 28
28 is a perfect number.
Sample Run 5:
Enter an integer greater than 1> 30
1 + 3 + 5 + 6 + 10 + 15 <> 30
30 is not a perfect number.

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{

int n;

cout << "Enter an integer greater than 1 >" ;

cin >> n;

if(n<=0)

{

cout << " The number that you enter must be greater than 1.";

system("pause");

return 0;

}

int sum=0;

for(int i=1; i<n; i++)

{

if(n%i ==0)

{

cout << i << " + ";

sum = sum + i;

}

}

cout << '' ;

if(sum == n)

{

cout << " = " << n << endl;

cout << n <<" is a perfect number."<<endl;

}

else

{

cout << " <>" << n<<endl;

cout << n <<" is not a perfect number."<<endl;

}

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