Ok I got an assignment thats to be handed in tonight. I finish the first one and completing the 2nd one now. I have figured out the hard part but a cout statement that i have is not printing in the order i specified.
Question:
The proper divisor of an integer n are the positive divisors less than n. a positive integer is said to be deficient, perfect or abundant number if the sum of its proper divisors are less than, equal to, or greater than the number respectively. For example, 8 is deficient because its proper divisors are 1,2, and 4 and 1 + 2 + 4 < 8; 6 is perfect because 1 + 2 + 3 =6; 12 is abundant because 1 + 2 + 3 +4 +6 > 12. Write a program that classifies n as being deficient, perfect, or abundant for n=20 to 30, then for n=400 to 500 and finally for n=8120 to 8130.
Code:
Output:#include <iostream>
using namespace std;
int n;
char check (int r);
/*
*
*/
int main(int argc, char** argv) {
int r1 = 0, r2, r3;
cout << "Below will be printed the Proper Divisors" << endl;
sleep(5);
for (n = 20; n >= 20 && n <=30; n++) {
cout << "Integer " << n << ":";
for (int d = 1; d < n; d++) {
if (n % d == 0) {
r1 = r1 + d;
cout << d << ", ";
}
}
cout << " = " << r1 << ". It is " << check(r1) << endl;
r1 = 0;
}
return 0;
}
char check (int r) {
if (r < n){
cout << "Deficient";
}
else if (r == n) {
cout << "Perfect";
}
else {
cout << "Abundant";
}
}
So as you can see the words Abundant, Deficient and Perfect should be printer at the very end, but for some reason it printing else where.Below will be printed the Proper Divisors
Integer 20:1, 2, 4, 5, 10, Abundant = 22. It is *
Integer 21:1, 3, 7, Deficient = 11. It is *
Integer 22:1, 2, 11, Deficient = 14. It is *
Integer 23:1, Deficient = 1. It is *
Integer 24:1, 2, 3, 4, 6, 8, 12, Abundant = 36. It is *
Integer 25:1, 5, Deficient = 6. It is *
Integer 26:1, 2, 13, Deficient = 16. It is *
Integer 27:1, 3, 9, Deficient = 13. It is *
Integer 28:1, 2, 4, 7, 14, Perfect = 28. It is *
Integer 29:1, Deficient = 1. It is *
Integer 30:1, 2, 3, 5, 6, 10, 15, Abundant = 42. It is