I'm trying to write a code that outputs the below as an extension to a program that output perfect numbers. I'm really struggling with the idea of arguments in C++ and need a little guidance so that the program outputs the correct numbers depending on the argument.
Extend the program so that the badness limit can be specified as a second command line argument. For example, print_perfect_numbers 100 3 should print 2 3 4 6 8 10 16 18 20 28 32 64.
my code so far:
#include <iostream>
#include <cstdlib>
using namespace std;
void print_perfect_numbers(int n, int b) {
for(int c = 2; c < n; c++) {
int t = 1;
for (int f = 2; f * f < c; f++) {
if (c % f == 0) {
t += f + c / f;
}
}
if (c == t) {
cout << c << " ";
}
else if ((c >= 2) && (t >= (c - b)) && (t <= (c + b))) {
cout << c << " ";
}
}
}
int main(int argc, char* argv[]) {
print_perfect_numbers(100,0);
print_perfect_numbers(100,3);
}
to add more context, the original code calculated the perfect numbers (numbers that have factors that equal the number ie 6 is perfect as its factors add up to it 1 + 2 + 3 = 6) up to 100. Quite Good numbers have a badness of a specified value (for the code im writing it is 3) where the factors of a number can equal the original number + or - the badness.
I can get the output of the numbers, however I'm trying to gain separate outputs as arguments for perfect numbers and quite good numbers up to 100.
my output currently is 6 28 2 3 4 6 8 10 18 20 28 32. i need to make it so the code outputs: 6 28 2 3 4 6 8 10 18 20 28 32 and no, a cout << endl; wont suffice.
pls help :)