这是我的一些代码:我无法弄清楚如何通过 perfectTest int 传递数组。我可以选择如果 n 为 -1 则打印出它是一个不足的数字,如果 n 为 0 则打印出它是一个完美的数字,如果 n 是 1 则打印出它是一个丰富的数字编号,但我需要在其中合并数组。我需要一些提示。
//prototype
int perfectTest(int n);
//function
int perfectTest(int n)
{ bool perfect;
int answer;
int perfectSum = 0;
perfect = false;
for(int i=1; i<=n/2; i++)
{
if(n % i==0)
perfectSum = i;
}
if(perfectSum == n)
perfect = true;
answer = perfectSum;
}
//main function
int main()
{
char option;
int n, m;
bool InService = true;
char perfectTestingOption;
int perfectNum;
bool perfect = true;
int factor;
while (InService == true)
{
cout << "\t\t\nWelcome! Choose an option below\n" << endl;
cout << "A = Perfect number testing" << endl;
cout << "B = Greatest common divisors and least common multiples" << endl;
cout << "C = Factorization of natural numbers" << endl;
cout << "Q = Quit the program\n" << endl;
cout << "Enter your choice:" << endl;
cin >> option;
if (option == 'A' || 'a')
{
cout << "\t\t\nWhich option would you like?\n" << endl;
cout << "1" << endl;
cout << "2" << endl;
cout << "3" << endl;
cout << "4" << endl;
cin >> perfectTestingOption;
if (perfectTestingOption == '1')
{
cout << "Enter a positive integer to check if it is a perfect number." << endl;
cin >> perfectNum;
perfectTest(0);
for( );
if (n == -1)
{
cout << "That number is a deficient number" << endl;
}
else if (n == 0)
{
cout << "That number is a perfect number" << endl;
}
else if (n == 1)
{
cout << "That number is a abundant number" << endl;
}
else
{
cout << "Number is invalid" << endl;
}
}