0
Why does the error do not come out even though I input 0 or 5 and above? Someone? Can you explain how to use &&?
#include <iostream> using namespace std; int main() { int x, operation, y; cout<< "Enter a Number"<< endl ; cin>> x; cin>> operation; cin>> y; if (operation<=0 && operation>=5) { cout<< "error" ; } if ( operation==1) { cout<< x+y ; } if ( operation==2) { cout<< x-y ; } if ( operation==3) { cout<< x*y ; } if ( operation==4) { cout<< x/y ; } return 0; }
4 Respostas
+ 5
&& means AND.
A number cannot be <= 0 and >= 5 at the same time
+ 5
You can use logical or operator instead.
+ 2
I think at the line
if(operation <=0 && operation>=5)..
Wont work because a can not be less than or equal to 0 and also be greater than or equal to 5
So i think a work around could be using “OR” instead of “AND”
So changing
&& —> ||