-3
When I run this program, I choose the whole 1
and enter the two if
's.
Why are you in n==1
and in the n!=1
at the same time?
#include<stdio.h>
int main(){
int n;
puts("ESCOLA UMA OPCAO");
puts("1. opcao1");
puts("2. opcao2");
scanf("%d", &n);
///////////////////////////////////////////////
if(n==1){
puts("opcao1");
}
///////////////////////////////////////////////
if(n==2){
puts("opcao2");
}
///////////////////////////////////////////////
if( n!=1 || n!=2)
{
puts("erro");
}
return 0;
}
Has not
else
some in this code.– Maniero
I don’t understand what your problem is, you could edit the question and clarify it a little more?
– gato
I think the intention there was to make E-if, not several ifs.
– user28595
@user3903094 will always enter the
if( n!=1 || n!=2)
, because the condition is always true. There is no wayn
was1
and2
at the same time. Ifn=1
, the partn!=2
is true, therefore the expression is true. Ifn=2
, the partn!=1
is true, therefore the expression is true. Ifn
other than1
and2
, both parts are true, therefore the expression is true. The error is in the implementation of logic, the operator "or" (||
) makes no sense in this context.– Bacco