c++语法错误,但不知错在哪里,高手指点!!
来源:百度知道 编辑:UC知道 时间:2024/05/29 03:33:05
#include <stdio.h>
void main()
{int x,y;
scanf("%d",&x);
if x<1
then y=x;
if x>=&&x<10
then y=2*x-1;
if x>=10
then y=3*x-11;
printf("%d,%d\n",x,y);
}
c:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(5) : error C2061: syntax error : identifier 'x'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(7) : error C2061: syntax error : identifier 'x'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(9) : error C2061: syntax error : identifier 'x'
有1个error无warning
void main()
{int x,y;
scanf("%d",&x);
if x<1
then y=x;
if x>=&&x<10
then y=2*x-1;
if x>=10
then y=3*x-11;
printf("%d,%d\n",x,y);
}
c:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(5) : error C2061: syntax error : identifier 'x'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(7) : error C2061: syntax error : identifier 'x'
C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\Cpp1.cpp(9) : error C2061: syntax error : identifier 'x'
有1个error无warning
1.c/c++中没有if then这个语法
正确语法是
if(条件成立)
{
}
else
{
}
修改为
if (x<1)
y=x;
if (x>=&&x<10)
y=2*x-1;
if (x>=10)
y=3*x-11;
2.if (x>=&&x<10)
这个地方.x>=什么????
你不会括弧啊?
if 语句后面的条件要用括号扩起来
例如if (x<1)
这样才行
是要计算分段函数吧
if then 是VB语法不是c
改好了
#include <stdio.h>
void main()
{
int x, y;
scanf("%d", &x);
if (x < 1)
{
y = x;
}
else if (x < 10)
{
y = 2 * x - 1;
}
else
{
y = 3 * x - 11;
}
printf("%d, %d\n", x, y);
}
........汗,老大