Write a program that answers the following questions: What numbers below 5000 are perfect? What odd numbers below 5000 are abundant? What are the relative proportions of deficient, abundant, and perfect numbers? 5000 should be in a global constant
So where did you have trouble with this?
this is what I have so far #include <iostream> using namespace std; const int maximumNumber=5000; int main() { for (testNumber=1; testNumber<=LIMIT; testNumber ++) { sum=sumOfDivisors(testNumber); if (sum<testNumber); { cout<< } deficientProportion=double(numOfDeficient)/double (LIMIT); int numOfDeficient; const int LIMIT=10; double deficientProportion; numOfDeficient=5; deficientProportion=double(numOfDeficient)/double(LIMIT);
Well, first off: ` for (testNumber=1; testNumber<=LIMIT; testNumber ++)` you have LIMIT being used before it is defined. The only perfect number below 5000 are 6, 28, and 496, so if it gets you thoise, it is finding perfect numbers. Typically you would break this sort of problem into smaller parts. A perfect number is a number that is a positive integer that is equal to the sum of its positive divisors. You can find a few formulas to test this. You just need to so the math to test a number. That sort of test would usually be done in a function.
Join our real-time social learning platform and learn together with your friends!