Problem:
I am practicing from my college's introduction problem set of creating a program where the user introduces four variables a
, b
, c
, d
and:
if a
is in (c; d)
AND b
isn't in (c; d)
the program should print a
, b
and a+b
; otherwise it should print a
, b
and a-b
:
I noticed that if the user introduces a
, b
such that BOTH statements are false it prints a+b
instead of a-b
. Why does it happen?
Attempt:
#include<iostream>
using namespace std;
int main()
{int a,b,c,d;
cout<<"Introduza a: ";
cin>>a;
cout<<"Introduzca b: ";
cin>>b;
cout<<"Introduzca c: ";
cin>>c;
cout<<"Introduzca d: ";
cin>>d;
if( (c<a<d) && ((b<c || d<b)))
{cout<<"a= " <<a <<"\n";
cout<<"b= " <<b << "\n";
cout<<"a+b= " <<a+b <<"\n";
}
else
{cout<<"a=" <<a <<"\n";
cout<<"b= " <<b <<"\n";
cout<<"a-b= " <<a-b <<"\n";}
}