c++语法错误,但不知错在哪里,高手指点!!
答案:3 悬赏:10 手机版
解决时间 2021-04-22 18:49
- 提问者网友:难遇难求
- 2021-04-22 12:54
#include
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
最佳答案
- 五星知识达人网友:孤老序
- 2021-04-22 13:19
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(条件成立)
{
}
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>=什么????
全部回答
- 1楼网友:琴狂剑也妄
- 2021-04-22 15:36
去掉then,加上括号,x>=&&改x>=1&& ,c不是vb
#include <stdio.h>
void main()
{int x,y;
scanf("%d",&x);
if ( x<1 )
y=x;
if ( x>=1&&x<10 )
y=2*x-1;
if ( x>=10 )
y=3*x-11;
printf("%d,%d\n",x,y);
}
- 2楼网友:山河有幸埋战骨
- 2021-04-22 14:17
if x<1 then y=x; if x>=&&x<10 then y=2*x-1; if x>=10
这里应该有 括号吧!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯