VC++内的函数内函数的问题
void CJDView::OnJsJd()
{
typedef struct stu
{
float score[5],d[5],aver;
}stu;
float fd(float sc,float jd)
{
switch(jd)
{
case 1.0:return 1.0;
case 1.5:if(sc>=65) return 1.5;
else return 1.0;
case 2.0:if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 2.5:if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 3.0:if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 3.5:if(sc>=85) return 3.5;
else if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 4.0:if(sc>=90) return 4.0;
else if(sc>=85) return 3.5;
else if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 4.5:if(sc>=90) return 4.5;
else if(sc>=85) return 3.5;
else if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 5.0:if(sc>=90) return 5.0;
else if(sc>=85) return 3.5;
else if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
case 5.5:if(sc>=90) return 5.5;
else if(sc>=85) return 3.5;
else if(sc>=80) return 3.0;
else if(sc>=75) return 2.5;
else if(sc>=70) return 2.0;
else if(sc>=65) return 1.5;
else return 1.0;
}
Dlg a;
if(!a.DoModal()) return;
stu s;
s.score[0]=a.m_s1;s.d[0]=a.m_s6;
s.score[1]=a.m_s2;s.d[1]=a.m_s7;
s.score[2]=a.m_s3;s.d[2]=a.m_s8;
s.score[3]=a.m_s4;s.d[3]=a.m_s9;
s.score[4]=a.m_s5;s.d[4]=a.m_s10;
s.aver=0;
int i;
for(i=0;i<5;i++)
{
s.aver+=fd(s.score[i],s.d[i])*s.d[i];
}
s.aver=s.aver/5;
a.m_s11=s.aver;
}
错误提示:'fd' : local function definitions are illegal
请问该怎么改啊?问题的原因是什么?
参考答案:函数定义不能嵌套