c语言程序编译问题 急! 编译通过,但运行报错是怎么回事?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
double m_grade;
int i;

i = 0;
while(i == 0)
{
printf("Please enter the scores\n",m_grade);
scanf("%lf",m_grade);
if(m_grade >= 0)
{
switch((int)(m_grade / 10))
{
case 10 :
case 9 :
{
printf("you get a A!");
break;
}
case 8 :
{
printf("you get a B!");
break;
}
case 7 :
{
printf("you get a C!");
break;
}
case 6 :
{
printf("you get a D!");
break;
}
default :
{
printf("you get a E!");
}
}
i = 1;

}
else
{
printf("Invalid values !");
system("cls");
}
}
return 0;
}
这是算法的哪一环节出问题了?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
    double m_grade;
    int i;
    i = 0;
    while(i == 0)
    {
        printf("Please enter the scores\n",m_grade);
        scanf("%lf",&m_grade);
        if(m_grade >= 0)
        {
            switch((int)(m_grade / 10))
            {
                case 10 :
                case 9  :
                    {
                        printf("you get a A!");
                        break;
                    }
                case 8  :
                    {
                        printf("you get a B!");
                        break;
                    }
                case 7  :
                    {
                        printf("you get a C!");
                        break;
                    }
                case 6  :
                    {
                        printf("you get a D!");
                        break;
                    }
                default :
                    {
                        printf("you get a E!");
                    }
            }
            i = 1;
        }
        else
        {
            printf("Invalid values !");
            system("cls");
        }
    }
    return 0;
}

注意程序中第14行scanf里面的m_grade前面我加了一个&

这个&是取地址运算符了  就是说把你当前输入的值送到m_grade的内存中去

你不加&就意味着输入的值没有地方放  只有加了& 才知道m_grade的地址

温馨提示:答案为网友推荐,仅供参考
相似回答