## bunyonb 2 years ago Write a program which given an integer n, classifies it as 'perfect', 'abundant' or 'deficient'. A number is perfect if the sum of its divisors ( excluding the number itself) is equal to the number, e.g. 6. A number is abundant if the sum of its divisors(excluding the number itself) is greater than the number, e.g. 12. A number is deficient if it is neither perfect nor abundant

1. time_to_learn

What do you need help with in this problem?

2. bunyonb

Give at least a pseudocode so that I can understand what to do

you should try this program out yourself first, before asking people to do it for you.

4. bunyonb

#include <iostream> 08 using namespace std; 09 10 int main() 11 { 12 int number,counter,total; 13 14 /* Asks for user input*/ 15 cout << "Welcome to the program Factors, this program check to see\n" 16 << "if the number you enter is deficent, perfect or abundant\n" 17 << "this program will read in numbers till you enter -1 and or negitive numbers"; 18 19 while (number > -1) 20 { 21 22 counter = 1; 23 cout << endl; 24 cout << "Please enter a Integer:\n"; 25 cin >> number; 26 cout << endl; 27 28 29 30 if (number % counter == 0) 31 { 32 total= counter + (number % counter); 33 34 cout << total << "+"; 35 counter++; 36 } 37 38 39 40 if (number < total) 41 { 42 cout << endl; 43 cout << number <<" is abundant\n"; 44 45 } 46 else if (number>total) 47 { 48 cout << endl; 49 cout << number << " is deficient\n"; 50 51 cout << endl; 52 } 53 else 54 { 55 cout << endl; 56 cout << number << " is Perfect\n"; 57 58 cout << endl; 59 } 60 61 } 62 63 cout<< endl << endl << endl; 64 system ("pause"); 65 return 0; 66 }

errrors?

6. bunyonb

Yeah

I mean, what are they?

8. bunyonb

its inaccurate

9. bunyonb

I think something is wrong with my values?

10. bunyonb

But i cannot put my finger on it...

The thing which is annoying is you have to add up EVERY possible combination. So for 12 it's 3 + 4 + 2 + 6....

12. bunyonb

its like adding prime factors of 12 excluding itself?

13. bunyonb

so if it is working on a number that isnt perfect It will work through the IF statements to see if it is abundant and another to see if it is deficient

14. bunyonb

I will post the code properly

15. bunyonb

#include <iostream> using namespace std; int main() { int number = 0,counter,total; /* Asks for user input*/ cout << "Welcome to the program Factors, this program check to see\n" << "if the number you enter is deficent, perfect or abundant\n" << "this program will read in numbers till you enter -1 and or negitive numbers"; while (number > -1) { cout << endl; cout << "Please enter a Integer:\n"; cin >> number; if (number < 0) { break; } cout << endl; counter = 1; total = 0; while (counter < number) { if (number % counter == 0) { cout << total << "+" << counter; total += counter; cout << "=" << total << endl; } counter++; } if (number < total){ cout << endl; cout << number <<" is abundant\n"; } else if (number>total) { cout << endl; cout << number << " is deficient\n"; cout << endl; } else { cout << endl; cout << number << " is Perfect\n"; cout << endl; } } cout<< endl << endl << endl; system ("pause"); return 0; }

16. bunyonb

#include <iostream> using namespace std; /*------------- -------------*/ int main () { int highNum, abunTotal, defTotal, perfTotal; abunTotal = 0; // sum of divisors more than the number itself defTotal = 0; // sum of divisors less than the number itself perfTotal = 0; // sum of divisors equal to the number itself int sum = 0; cout<< "Please enter a positive integer:"; cin>> highNum; for(int i = 1; i <= highNum; i++ ) { sum = 0; for(int j = 1; j < i; j++ ) { if((i % j) == 0) { sum += j; } } if ( sum == i) //the number is perfect { perfTotal++; cout << "PERFECT NUMBER: " << i << endl; } if ( sum < i) //the number is deficient { defTotal++; } if ( sum > i) //the number is abundant { abunTotal++; } } cout << "The perfTotal is:" << perfTotal << endl; cout << "The defTotal is:" << defTotal << endl; cout << "The abunTotal is:"<< abunTotal << endl; cout << endl; }