#include<stdio.h>
#include<stdlib.h>
double operand1, operand2, result;
int count;
char selected_operator;
void intro(void);
void selected_operator_(void);
void result_intro(void);
void result_(int operand);
int main(void)
{
intro();
scanf("%lf", &operand1);
intro();
scanf("%lf", &operand2);
printf("원하시는 연산기호를 입력하십시오\n");
getchar();
selected_operator = getchar();
selected_operator_();
result_intro();
system("pause");
return 0;
}
void intro(void)
{
printf("%d번째 숫자를 입력해주십시오.\n", count + 1);
count++;
}
void selected_operator_(void)
{
switch(selected_operator)
{
case('+'):
result = operand1 + operand2;
break;
case('-'):
result = operand1 - operand2;
break;
case('*'):
result = operand1 * operand2;
break;
case('/'):
result = operand1 / operand2;
default:
printf("다시 연산 기호를 입력해주십시오\n");
getchar();
selected_operator = getchar();
selected_operator_();
break;
}
}
void result_intro(void)
{
printf("\n\n\n답:%lf\n", result);
}
printf("%d번째 숫자를 입력해주십시오.n", count + 1); count++; ------------> printf(".........", ++count);
intro 보단 ask, query, question
selected_operator 줄여서 걍 opcode 나 command 하든지. (명령어 코드를 이야기 할 때 쓰지만)
네이밍 하기가 너무 어려운듯
함수의 이름으로 selected_operator_ 는 부적합. 그냥 operation 으로 하든지, solve 로 하든지, run 뭐 등등.
그리고 operand1, 2, opcode를 run(operand1, opcode, operand2) 로 처리하도록 하는게 좋을듯.
전역변수로 정의하지 말란 소리.
그러면 함수만 떼어다 다른 소스코드에다 써먹을 수 있잖아.
따로 구성한 서브루틴(함수) 에서 출력 코드를 넣는건 재사용성을 떨어뜨려요.
그러니 에러가 있다면 false 를 리턴하게 하고 정상실행시 true 를 리턴하게 해 주는게 나을듯. 아니면 에러코드를 리턴하든지.
전역함수로하기전에 void selected_operator_(char opcode) 로함수설정하고
재귀 구조를 안에 넣은건 이색적인데, 결국 재사용성만 떨어뜨림. 밖에서 싸주는게 나아요.
selected_operator_(selected_operator); 하고 부르니까 에러나던데
result_intro 같은 함수는 타이핑 비용에 비해 득이 없다. 재사용여지도 없고.
그건 니가 잘못짜서 일거야. '무슨 에러인지 보는것' 이 중요해.
그0개의 항을 가져올수없는 함수입니다 엿나
result_intro는 생각해보니 그냥 메인에 써도 똑같겠구나 ...
함수를 여러개하는게 메인함수를 보기편하게할뿐만아니라 재사용성을 높이는거였구나
그냥 메인함수만 깔끔하게하는용도인지 알고 다 다른함수로 썻었음...
에러메시지에 힌트가 충분히 있을테니 잘 대화해봐 : )
알겠어 일단을 수정해볼게!
http://dblack.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다.