這個問題在這里已經有了答案: 鏈接多個大于/小于運算子 (6 個回答) 23 小時前關閉。
輸入檢查狀態的值時,else if除非if僅在第一個條件中滿足條件,否則該程式中的 不會給出輸出。
#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;
}
}
}
}
請注意,當我使用if代替else if程式運行并給出輸出時。有什么問題?
uj5u.com熱心網友回復:
您不能使用條件運算式,例如PA<=pin<=PA 7'. In C, operator <= evaluates left to right so the program will first evaluatePA<=pin , which will be true orfalse , then compares this result to pin as eithertrue<=pin or 'false<=pin。
應修改這些運算式以包括&&. 例如,替換
if(PA<=pin<=PA 7)
和
if((PA<=pin) && (pin<=PA 7))
這將首先檢查PA<=pin然后pin<=PA 7。如果兩者都計算為,true則if塊將被執行。
必須對PB、PC和進行類似的更改PD。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/343892.html
上一篇:打字稿不警告可能未定義的陣列?
