我已经输入了该功能,但我无法获得输出。谁能帮我。它必须使用预定义的功能。我的程序正在运行,但它有一些错误,所以请帮助我。
#include <iostream>
using namespace std;
float largeNum (float a, float b)
{
float largeNum;
if(a>b)
cout<<"a is larger";
if(b>a)
cout<<"b is larger";
return (largeNum);
}
int main()
{
float num1, num2;
cout<<"Enter number";
cin>>num1;
cout<<"Enter number";
cin>>num2;
cout<<largeNum<< "is larger"<<endl;
return 0;
}
答案 0 :(得分:2)
#include <iostream>
using namespace std;
float largeNum (float a, float b)
{
if(a>b)
return a;
return b;
}
int main()
{
float num1, num2;
cout<<"Enter number";
cin>>num1;
cout<<"Enter number";
cin>>num2;
cout<<largeNum(num1, num2)<< "is larger"<<endl;
return 0;
}
答案 1 :(得分:2)
尝试将代码更改为以下内容。你没有给largeNum任何东西,所以你不能退货。
#include <iostream>
using namespace std;
float largeNum(float a, float b)
{
if (a > b)
cout << "a is larger";
if (b > a)
cout << "b is larger";
return 0;
}
int main()
{
float num1, num2;
cout << "Enter number";
cin >> num1;
cout << "Enter number";
cin >> num2;
largeNum(num1, num2);
getchar();
getchar();
return 0;
}
答案 2 :(得分:1)
#include <iostream>
using namespace std;
void largeNum(float a, float b)
{
if (a > b)
{
cout << a << " larger";
}
if (b > a)
{
cout << b << " larger";
}
}
int main()
{
float num1, num2;
cout << "Enter number";
cin >> num1;
cout << "Enter number";
cin >> num2;
largeNum(num1,num2);
return 0;
}
在你的代码中你只是定义了函数,但是你没有调用这个函数main,这就是为什么你会得到错误