| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1646 人关注过本帖
标题:求助:“当x位于1到20之间时,将x的值赋给变量y;如果x不在这个范围内,则保 ...
只看楼主 加入收藏
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 8楼 dani337
按你这样编译的时候提示有错误
In file included from C:\DEV-C_~1\Include\windows.h:78,
                 from e:\c\4112练~1.c:2:
C:\DEV-C_~1\Include\windef.h:153: parse error before `#'
C:\DEV-C_~1\Include\windef.h:153: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:154: parse error before `#'
C:\DEV-C_~1\Include\windef.h:154: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:155: parse error before `#'
C:\DEV-C_~1\Include\windef.h:155: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:156: parse error before `#'
C:\DEV-C_~1\Include\windef.h:156: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:157: parse error before `#'
C:\DEV-C_~1\Include\windef.h:157: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:158: parse error before `#'
C:\DEV-C_~1\Include\windef.h:158: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:159: parse error before `#'
C:\DEV-C_~1\Include\windef.h:159: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:160: parse error before `#'
C:\DEV-C_~1\Include\windef.h:160: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:161: parse error before `#'
C:\DEV-C_~1\Include\windef.h:161: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:162: parse error before `#'
C:\DEV-C_~1\Include\windef.h:162: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:163: parse error before `#'
C:\DEV-C_~1\Include\windef.h:163: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:164: parse error before `*'
C:\DEV-C_~1\Include\windef.h:164: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:165: parse error before `#'
C:\DEV-C_~1\Include\windef.h:165: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:166: parse error before `#'
C:\DEV-C_~1\Include\windef.h:166: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:167: parse error before `#'
C:\DEV-C_~1\Include\windef.h:167: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:168: parse error before `HMODULE'
C:\DEV-C_~1\Include\windef.h:168: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:169: parse error before `#'
C:\DEV-C_~1\Include\windef.h:169: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:170: parse error before `#'
C:\DEV-C_~1\Include\windef.h:170: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:171: parse error before `#'
C:\DEV-C_~1\Include\windef.h:171: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:172: parse error before `#'
C:\DEV-C_~1\Include\windef.h:172: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:173: parse error before `#'
C:\DEV-C_~1\Include\windef.h:173: warning: data definition has no type or storage class
C:\DEV-C_~1\Include\windef.h:174: parse error before `#'
2011-10-25 22:21
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:0 
回复 8楼 dani337
if((1<=x)&&(x<=20))/*   x=8,此处为假,不执行if(){}语句中的y=x;因为y是全局变量,所以y的默认值为0   */

[ 本帖最后由 laznrbfe 于 2011-10-25 22:27 编辑 ]
2011-10-25 22:22
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:0 
回复 11楼 dani337
我用VC++6.0编译的。
2011-10-25 22:24
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 9楼 laznrbfe
多谢了哦。。就是你说的这样。哈。终于解决了。。
2011-10-25 22:26
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:0 
回复 14楼 dani337
我的if语句写错了,应该是:if((1<=x)&&(x<=20))
2011-10-25 22:28
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
不好意思刚说错了。。是10楼的帮我解决的。。他的这个输出的是对的。。
2011-10-25 22:30
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
回复 12楼 laznrbfe
谢谢了。。你的那个思路好像也是对的。我等下去试试。不过我是用Dev-C++  编译的。可能#include<windows.h>这个不能用吧。
2011-10-25 22:34
dani337
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2011-10-25
收藏
得分:0 
我好像就是 if((1<x)&&(x>=20))
这里写错了。。 if((1<x)&&(<=20))  难怪找半天找不到问题。
2011-10-25 22:37
黙然
Rank: 1
等 级:新手上路
帖 子:3
专家分:5
注 册:2011-10-24
收藏
得分:0 
if条件不满足,不进入if的执行语句,直接跳过,而y没有赋值,那么输出的结果是默认值,不同的编译器产生不同的默认值,所以,结果是不可预期的。
2011-10-25 22:57
七夜忧
Rank: 2
等 级:论坛游民
威 望:1
帖 子:41
专家分:50
注 册:2011-7-14
收藏
得分:0 
把 printf("\n打印y:%d\n",y );放到if里去,不过“打印”这两个字最好改英文什么的。
2011-10-25 23:16
快速回复:求助:“当x位于1到20之间时,将x的值赋给变量y;如果x不在这个范围内 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018042 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved