When entering values that check the states, the else if
in this program does not give an output unless the condition is fulfilled in the first if
condition only.
#include<stdio.h>
#include"STD_TYPES.h"
#include"REG.h"
#include"BIT_MATH.h"
#define PA 40
#define PB 63
#define PC 20
#define PD 10
void main (void){
int pin ;
printf("Enter The Pin Number \n");
scanf("%d",&pin);
if (PA<=pin<=PA+7){
for(int i=0 ;i<=7;++i){
if(pin==PA+i){
printf("your are in the port A and pin %d \n",i);
break;
}
}
}else if(PB<=pin<=PB+7){
for(int i=0 ;i<=7;++i){
if(pin==PB+i){
printf("your are in the port B and pin %d \n",i);
break;
}
}
}else if(PC<=pin<=PC+7){
for(int i=0 ;i<=7;++i){
if(pin==PC+i){
printf("your are in the port C and pin %d \n",i);
break;
}
}
}else if(PD<=pin<=PD+7){
for(int i=0 ;i<=7;++i){
if(pin==PD+i){
printf("your are in the port D and pin %d \n",i);
break;
}
}
}
}
Note that when I use if
instead of else if
the program runs and gives output. What's the problem?
Aucun commentaire:
Enregistrer un commentaire