This is a half-done code, which I am stuck with when the input is: i1 = 3, i2 = 5, i3 = 7.
#include < iostream >
#include < string >
#include < vector >
#include < algorithm >
#include < cmath >
using namespace std;
//Comparing Integers
int main()
{
int i1;
int i2;
int i3;
cout << "Enter 3 integers: ";
cin >> i1 >> i2 >> i3;
int diff_3_1 = i3 - i1;
int diff_3_2 = i3 - i2;
if (diff_3_1 >> diff_3_2){
cout << i1 << " is smaller than " << i2 << '\n';
}
if (diff_3_1 << diff_3_2){
cout << i2 << " is smaller than " << i1 << '\n';
}
}
Both output from the two 'if' operators are printed out. I can't find the error. I know that by replacing the second operator with 'else if' would work. However, I would like to know my error in this case.
Aucun commentaire:
Enregistrer un commentaire