如何将值返回到另一个函数
How to return a value to another function
我似乎无法弄清楚如何做这项工作,随着我几天的尝试,任何帮助都将不胜感激:(
#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,(返回输入,sum)错误如下:表达结果未使用[-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;
}
我认为您的意图是..
#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;
}
将CubeOfDigits函数从(int)CubeofDigits更改为(void)CubeofDigits,然后从CubeofDigits函数末尾删除返回语句。>
相关文章:
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 将 N-arg 函数包装到另一个函数中
- C++从另一个函数退出函数
- 视觉我希望一个函数在另一个函数C++中进行计算
- 在另一个函数 (c++) 中调用变量
- 如何在另一个函数中使用返回值作为参数?
- 如何包装一个函数以适应另一个函数的所需类型
- 当使用我在一个函数、另一个函数中修改的数组时,在我的输出中得到一个奇怪的负数
- 如何将 lambda 函数作为参数发送到另一个函数
- 将可变参数从一个函数传递到另一个函数
- 有没有办法在另一个函数中加入线程?(即超出其自身范围)
- 存储另一个函数返回的布尔数组时遇到问题
- 我正在尝试将表的地址传递给要在另一个函数中使用的指针,但得到不兼容的指针类型
- 如何在C++中提供模板化函数作为另一个函数的参数,默认值?
- 将作业传递给另一个函数,而不会延迟 arduino
- 编译器在C++中调用另一个函数时,在参数中查找已删除的构造函数
- 将参数从一个函数传递到另一个函数(没有模板) - C++
- 如何利用指针从一个函数到另一个函数?
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 在 c++ 中,如何将当前函数的所有参数传递给另一个函数?