-3
这是我的任务:“编写一个函数,它可以找到两个整数中较大的一个输入(在主程序中),但允许您使用传递引用来更改函数中整数的值。”我一直在试图找出我的代码有什么问题,但我不知道它是什么。有人请帮助我!这个任务是今晚的! 这里是我的代码的现在:错误:控件达到非void函数结束?
#include <iostream>
using namespace std;
int change(int& x, int& y)
{
int temp=0;
cout << "Function(before change): " << x << " " << y << endl;
temp = x;
x = y;
y = temp;
cout << "Function(after change): " << x << " " << y << endl;
}
int main()
{
int x,y;
cout << " Please Enter your first number: ";
cin >> x;
cout << " Please Enter your second number: ";
cin >> y;
if (x > y)
cout << x << " is greater than " << y << endl;
if (x < y)
cout << y << " is greater than " << x << endl;
if (x == y)
cout << x << " is equal to " <<y << endl;
cout << "Main (before change): " << x << " " << y << endl;
change(x, y);
cout << "Main (after change): " << x << " " << y << endl;
system("Pause");
return 0;
}
您指定'change'将返回一个'int'但你永远不返回任何内容。 – NathanOliver
关键字:Return value。 – deviantfan