|
查看: 983|回复: 1
|
c++ 初学者需要你们的帮忙...
[复制链接]
|
|
|
发表于 23-8-2008 01:28 PM
|
显示全部楼层
当你的 if() 之后的 statement 是超过1行(一行的意思是“从statement的开始到 ; (semicolon)出现为止)的话,请用curly bracket {} 来包围着你对应该 if() 的 statement。- if (integer1 <= 40)
- {
- total1 = integer1 * 10;
- cout << "total = " <<total1;
- }
- 以及
- if (integer1 > 40)
- {
- total2 = integer1 * 10;
- total3 = (integer1 - 40) * 15 + total2;
- cout << "total = " << total3;
- }
复制代码 否则compiler只会把 if()之后的第一行statement 和 if()联系起来,其他的都会被当作不相干的独立statement 。
还有,以后当你要在论坛放出你的源代码,请使用 code block,也就是
[ code ] 你的源代码 [ /code ]
这会让你的源代码比较容易阅读,就好像我在上面使用的那样。
[ 本帖最后由 geekman 于 23-8-2008 01:31 PM 编辑 ] |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|