我正在看一个计算3个数字平均值的程序
#define EXIT_SUCCESS 0
Run Code Online (Sandbox Code Playgroud)
使return EXIT_SUCCESS;工作没有错误(在包含标题下).什么是使用的目的#define EXIT_SUCCESS 0和return EXIT_SUCCESS;和没有任何替代品吗?是return 0;吗?感谢您的时间.
这是我正在查看的程序的代码:
#include <iostream>
#define EXIT_SUCCESS 0
using namespace std;
int main()
{
// prototypes:
float add_and_div(float, float, float);
// variables:
float x, y, z;
float result;
cout << "Enter three floats: ";
cin >> x >> y >> z;
// continue the program here
result = add_and_div( x, y, z );
cout<< "Average is \n" << result;
return EXIT_SUCCESS;
}
// function …Run Code Online (Sandbox Code Playgroud) 这是我正在进行的任务.我很确定这是我错过的一些小事,但是看到我在为其他课程学习后我正努力工作,我相信另一组眼睛可以帮助我.我应该有这样的事情:
please enter first value---> 5.2
please enter second value---> 1.0
please enter third value-->7.1
smallest value: 1.0
largest value: 7.1
Run Code Online (Sandbox Code Playgroud)
然而,得到一些奇怪的数字,如002C128F为最小值,002C128A为最大值.我将不胜感激任何反馈.我不是要求完成我的作业.我只是想得到一些指导,看到我被卡住了.也许我的if陈述是错的?感谢您的时间.
#include <iostream>
using namespace std;
double min2 (double &a, double &b,double &c)
{
double min=0;
if(a<b)
min= a;
else
min=b;
if (c<b)
min=c;
return min;
}
double max2(double &a, double &b, double &c)
{
double max=0;
if(a>b)
max=a;
else
max=b;
if (c>b)
max=c;
return max;
}
int main()
{
double a,b,c=0;
min2(a,b,c);
max2(a, b, c);
cout …Run Code Online (Sandbox Code Playgroud)