これが私のコードの一部です:perfectTestintを介して配列を渡す方法を理解するのに問題があります。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;
}
}