c 언어 어디가 잘못된 걸까요?
The purpose of the following program is to check input. It is only supposed to accept a value between 0 and 20, and it should continually ask for input until the correct numbers are entered. However, there is a bug in it.
#include
#define TRUE 1
#define FALSE 0
int main(void)
{
int correct, inputint;
inputint = -1;
correct = FALSE;
while (!correct) {
if (0 < inputint < 20) {
printf("Thank you.\n");
correct = TRUE;
} else {
printf("Enter an integer ");
printf("between 0 and 20: ");
scanf("%d", &inputint);
}
}
return 0;
}
a. Fix the bug so that the program behaves as stated above.
영어책 문제 인데요.
숫자적어야 하는 부분이 나오고 그 뒤에
판별해야 하는건 알겠는데 어디를 어떻게 바꿔야 할지
모르겠습니다.
0 < inputint < 20
inputint 값에 상관없이 결과가 항상 true로 나옵니다.
0 < inputint -> 0 or 1
0 or 1 < 20 -> true
0 < inputint && inputint < 20 과 같은 식으로 써야 합니다.
소스코드 넣을 때는 https://kldp.org
소스코드 넣을 때는 https://kldp.org/node/158191 참고하시고,
영어 번역 해달라는 얘긴 아니겠죠?
0 < inputint < 20
이런 표현을 수학책에서는 일반적으로 쓰는데,
C 프로그램언어에서는
또는
이런 식으로 씁니다.
세벌 https://sebuls.blogspot.kr/
감사합니다!!
감사합니다!!
댓글 달기