我似乎无法弄清楚如何使这项工作得到任何帮助将会非常感激,因为我已经尝试了几天:(
#include <iostream>
#include <math.h>
using namespace std;
int input;
int sum;
int number1;
int number2;
int number3;
void isArmstrong (int input, int sum)
{
if (input == sum)
cout << input << " is an Armstrong number" << endl;
if (input != sum)
cout << input << " is not an Armstrong number" << endl;
}
cubeOfDigits不返回输入和总和为isArmstrong,(返回输入,求和)错误如下:表达式结果未使用[-Wunused-value]
int cubeOfDigits (int input, int sum, int number1, int number2, int number3)
{
cout << "Enter an integer between 0-999" << endl;
cin >> input;
number1 = input / 100;
number2 = input % 100;
number3 = number2 % 10;
sum = pow(number1, 3) + pow(number2, 3) + pow(number3, 3);
isArmstrong(input, sum);
return input,sum;
}
主要调用cubeOfDigits
int main(void)
{
cout << "Welcome" << endl;
cubeOfDigits(input, sum, number1, number2, number3);
return 0;
}
答案 0 :(得分:0)
将cubeofdigits函数从(int)cubeofdigits更改为(void)cubeofdigits,然后从cubeofdigits函数的末尾删除return语句。然后它必须工作。
答案 1 :(得分:0)
我认为你的意图是......
#include <iostream>
#include <math.h>
using namespace std;
int input;
int sum;
int number1;
int number2;
int number3;
void isArmstrong(int input, int sum){
if(input == sum)
cout << input << " is an Armstrong number" << endl;
if(input != sum)
cout << input << " is not an Armstrong number" << endl;
}
int cubeOfDigits (int input)
{
number1 = input/100;
number2 = input % 100;
number3 = number2 % 10;
number2 = number2/10;
sum = pow(number1,3) + pow(number2,3) + pow(number3,3);
return sum;
}
int main(void){
cout << "Welcome" << endl;
cout << "Enter an integer between 0-999" << endl;
cin >> input;
isArmstrong(input,cubeOfDigits(input));
return 0;
}