c语言中出现undeclared identifier ,求帮助啊!!
程序如下:#include<stdio.h>#include<math.h>intmain(void){do{doublea,b,c;doubledelte;double...
程序如下:
# include <stdio.h>
# include <math.h>
int main (void)
{
do
{
double a , b , c ;
double delte ;
double x1 , x2 ;
char ch ;
printf ("请输入A的值:\n");
scanf ("%lf", &a);
printf ("请输入B的值:\n");
scanf ("%lf", &b);
printf ("请输入C的值:\n");
scanf ("%lf", &c);
delte = b * b - 4 * a * c;
if (delte > 0)
{
x1 = ((-b) + sqrt(delte)) / (2 * a);
x2 = ((-b) - sqrt(delte)) / (2 * a);
printf ("该方程有两个解: x1 = %lf,x2 = %lf", x1 ,x2);
}
else if (delte == 0)
{
printf ("该方程有唯一解:\n");
x1 = x2 =-b / 2 * a ;
printf ("x1 = x2 =%lf",x1);
}
else
{
printf ("该方程无解:\n");
}
printf ("还要计算吗(Y/N):");
scanf (" %c",&ch);
}
while( 'y'==ch );
return 0;
}
为什么提示在while这一行出现错误,错误提示如下:
Compiling...
1.cpp
E:\1.cpp(40) : error C2065: 'ch' : undeclared identifier
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)
大致意思就是ch没有定义变量,可是明明在第十行将ch定义为char了啊, 小弟初学C,求帮助,详细解答一下,谢谢. 展开
# include <stdio.h>
# include <math.h>
int main (void)
{
do
{
double a , b , c ;
double delte ;
double x1 , x2 ;
char ch ;
printf ("请输入A的值:\n");
scanf ("%lf", &a);
printf ("请输入B的值:\n");
scanf ("%lf", &b);
printf ("请输入C的值:\n");
scanf ("%lf", &c);
delte = b * b - 4 * a * c;
if (delte > 0)
{
x1 = ((-b) + sqrt(delte)) / (2 * a);
x2 = ((-b) - sqrt(delte)) / (2 * a);
printf ("该方程有两个解: x1 = %lf,x2 = %lf", x1 ,x2);
}
else if (delte == 0)
{
printf ("该方程有唯一解:\n");
x1 = x2 =-b / 2 * a ;
printf ("x1 = x2 =%lf",x1);
}
else
{
printf ("该方程无解:\n");
}
printf ("还要计算吗(Y/N):");
scanf (" %c",&ch);
}
while( 'y'==ch );
return 0;
}
为什么提示在while这一行出现错误,错误提示如下:
Compiling...
1.cpp
E:\1.cpp(40) : error C2065: 'ch' : undeclared identifier
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)
大致意思就是ch没有定义变量,可是明明在第十行将ch定义为char了啊, 小弟初学C,求帮助,详细解答一下,谢谢. 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询