Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

What do you need help with in this problem?

OpenStudy (anonymous):

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

OpenStudy (konradzuse):

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

OpenStudy (anonymous):

#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 }

OpenStudy (konradzuse):

errrors?

OpenStudy (anonymous):

Yeah

OpenStudy (konradzuse):

I mean, what are they?

OpenStudy (anonymous):

its inaccurate

OpenStudy (anonymous):

I think something is wrong with my values?

OpenStudy (anonymous):

But i cannot put my finger on it...

OpenStudy (konradzuse):

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

OpenStudy (anonymous):

its like adding prime factors of 12 excluding itself?

OpenStudy (anonymous):

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

OpenStudy (anonymous):

I will post the code properly

OpenStudy (anonymous):

#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; }

OpenStudy (anonymous):

#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; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!