Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bunyonb

  • one year 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

  • This Question is Closed
  1. time_to_learn
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What do you need help with in this problem?

  2. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  5. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    errrors?

  6. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah

  7. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I mean, what are they?

  8. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    its inaccurate

  9. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think something is wrong with my values?

  10. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    But i cannot put my finger on it...

  11. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    its like adding prime factors of 12 excluding itself?

  13. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I will post the code properly

  15. bunyonb
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #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
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  17. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.