#include<stdio.h>
float docalculate(char opertor,float operandA,float operandB);
float doAdd(float operandA,float operandB);
float doSub(float operandA,float operandB);
float doMul(float operandA,float operandB);
float doDiv(float operandA,float operandB);
int mian()
{
float result=0;
result=docalculate('+',10.0,20);
printf("10+20=%f\n",result);
result=docalculate('-',35,19);
printf("35-19=%f\n",result);
result=docalculate('*',12.3,4.5);
printf("12.3x4.5=%f\n",result);
result=docalculate('/',100/2.5);
printf("100/2.5=%f\n",result);
return 0;
}
float docalculate(char op,float operandA,float operandB)
{
float(*pcalculate)(float operandA,float operandB);
switch(op){
case '+': pcalculate=doAdd;break;
case '-': pcalculate=doSub;break;
case '*': pcalculate=doMul;break;
case '/': pcalculate=doDiv;break;
};
return pcalculate(operandA,operandB);
}
float doAdd(float operandA,float operandB)
{
return operandA+operandB;
}
float doSub(float operandA,float operandB)
{
return operandA-operandB;
}
float doMul(float operandA,float operandB)
{
return operandA*operandB;
}
float doDiv(float operandA,float operandB)
{
return operandA/operandB;
}
이식에서 틀린게 뭔지아시나요 ? ㅠㅠ
독학중이라 모르는게 잇어도 제대로 알방법이 없습니다
지적해주는김에 재귀함수에 대한 자세한설명해줄실분잇으신가요 ? ㅠㅠ
1>c:\users\administrator\documents\visual studio 2010\projects\e\e\d.cpp(18): warning C4305: '인수' : 'double'에서 'float'(으)로 잘립니다.
1>c:\users\administrator\documents\visual studio 2010\projects\e\e\d.cpp(21): error C2660: 'docalculate' : 함수는 2개의 매개 변수를 사용하지 않습니다.
이런게 뜨네요 그리고 float함수 결과나올때 소수점 뒷자리수는 왜 안나오는거죠 ?