如何比较两个小时?我尝试使用下面的代码,但它给了我两次true
,但它应该给false
和true
:
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
bool earlierEqual(int h1, int m1, int s1, int h2, int m2, int s2)
{
if(h1 <= h2)
{
return true;
}
else
{
if(m1 <= m2)
{
return true;
}
else
{
if(s1 <= s2)
{
return true;
}
else
return false;
}
}
}
bool laterEqual(int h1, int m1, int s1, int h2, int m2, int s2)
{
if(h1 >= h2)
{
return true;
}
else
{
if(m1 >= m2)
{
return true;
}
else
{
if(s1 >= s2)
{
return true;
}
else
return false;
}
}
}
int main()
{
int h1 = 12, m1 = 4, s1 = 29;
int h2 = 11, m2 = 12, s2 = 1;
// false
cout << earlierEqual(h1, m1, s1, h2, m2, s2) << "\n";
// true
cout << laterEqual(h1, m1, s1, h2, m2, s2) << "\n";
return 0;
}