본문 바로가기
C

연료 탱크 시뮬레이션

by KWONE 2024. 2. 15.

  
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
int gas,input;
gas = 100;
while (1) {
if (gas < 20) {
printf("현재 연료량: %d\n", gas);
printf("(경고) 연료가 20리터 미만입니다.\n");
}
else
printf("현재 연료량: %d\n", gas);
printf("연료 충전은 +, 소모는 -로 입력해주세요: ");
scanf("%d", &input);
gas = gas + input;
printf("\n");
}
return 0;
}

 

문제에 언제 끝내야하는지 명시되어있지않아서..무한반복