我正在制作一个程序,您需要使用 bool 函数来确定三个数字在用户输入时是否按升序排列。但是,bool 函数的计算结果始终为真。我错过了什么?这是我的代码:
#include <iostream>
#include <string>
using namespace std;
bool inOrder(int first, int second, int third)
{
if ((first <= second) && (second <= third))
{
return true;
}
else
{
return false;
}
}
int main()
{
int first, second, third;
cout << "You will be prompted to enter three numbers." << endl;
cout << "Please enter your first number: ";
cin >> first;
cout << "Please enter your second number: ";
cin >> second;
cout << "Please enter your third and final number: ";
cin >> third;
cout << endl;
inOrder(first, second, third);
if (inOrder)
{
cout << "Your numbers were in ascending order!" << endl;
}
else
{
cout << "Your numbers were not in ascdending order." << endl;
}
return 0;
}