C++ 最小和最大值c++;

C++ 最小和最大值c++;,c++,floating-point,max,min,C++,Floating Point,Max,Min,所以我有一些代码,我正在为一个赋值而写,我一直在寻找3个浮点值中的最小值和最大值。我目前得到的错误 /usr/include/c++/4.9/bits/predefined_ops.h:121:39:错误:一元数“”的类型参数无效(具有“float”) {返回bool(_M_comp(_it1,*_it2));} 这是我当前的代码: #include <iostream> #include <string> #include <algorithm> usin

所以我有一些代码,我正在为一个赋值而写,我一直在寻找3个浮点值中的最小值和最大值。我目前得到的错误

/usr/include/c++/4.9/bits/predefined_ops.h:121:39:错误:一元数“”的类型参数无效(具有“float”) {返回bool(_M_comp(_it1,*_it2));}

这是我当前的代码:

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

//Name: Tanner Langan
//Student Number: 300224340
//Date: 2//16/2017
//Assignment 3


int main()
{
char c1;
float x1,x2,x3;

cout << "Please Enter 1 character and 3 float numbers. One at a time" << endl;
cout << "You must choose either X, N, V, or S for the character." << endl;
cout << "If you choose X the result displayed will be the the maximum of x1, x2, and x3" << endl;
cout << "If you choose N the result displayed will be the the minimum of x1, x2, and x3" << endl;
cout << "If you choose V the result displayed will be the the average of x1, x2, and x3" << endl;
cout << "If you choose S the program will terminate.";
cin >> c1;
cin >> x1;
cin >> x2;
cin >> x3;

while (c1 != 'S')
{
if(c1 == 'X' || c1 == 'x')
{
cout << "The max is" << std::max_element(x1,x2,x3) << endl;
main();
}
if(c1 == 'N' || c1 == 'n')
{

cout << "The min is" << std::min_element(x1,x2,x3) << endl;
main();
}
if(c1 == 'V' || c1 == 'v')
{
cout << "The average is" << (x1+x2+x3)/3 << endl;
main();
}

}
return 0;

 }
#包括
#包括
#包括
使用名称空间std;
//姓名:Tanner Langan
//学号:300224340
//日期:2017年2月16日
//作业3
int main()
{
字符c1;
浮动x1、x2、x3;

不能并且不能像你想的那样工作。它们实际上将迭代器带到序列和比较器,而不仅仅是数字。它们还返回迭代器,而不是值,所以在尝试随机调用函数之前,请阅读文档并了解如何使用它们。我链接的页面上有一些示例应该可以帮助你。

你需要使用
std::min
std::max