平均标记错误,begginer CODEBLOCKS [英] Average marks error ,begginer CODEBLOCKS

查看:151
本文介绍了平均标记错误,begginer CODEBLOCKS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已经在C代码中用C代码写了这段代码作为我作业的一部分,我得到了错误,但我不明白为什么。有人请帮助我吗?




1 #include

2 #include

3

4 int main()

5 {

6 int m1,m2,m3;

7 scanf(%d%d%d,&m1,&m2,&m3 );

8浮动ave =(m1 + m2 + m3)/3.0;

9

10 if(ave< 60);

11

12 printf(失败);

13其他printf(通行证);

14返回0;

15

16}





---- ---------------------------

错误我得到了







|| === Build:在avmarks中调试(编译器:GNU GCC编译器)=== |

| 10 |警告:if语句有空体[-Wempty-body] |

| 10 |注意:将分号放在单独的行上以使此警告静音|

13 |错误:预期表达式|

|| ===构建失败:1个错误,1个警告(0分钟,0秒(秒))=== |

Hi all, i have written this code in C in codeblocks as a part of my homework and i get errors but i don"t understand why.can someone please help me?


1 #include
2 #include
3
4 int main()
5 {
6 int m1, m2, m3;
7 scanf ("%d %d %d", &m1, &m2, &m3);
8 float ave=(m1+m2+m3)/3.0;
9
10 if (ave<60);
11
12 printf("Failed");
13 else printf("Pass");
14 return 0;
15
16 }


-------------------------------
errors i get



||=== Build: Debug in avmarks (compiler: GNU GCC Compiler) ===|
|10|warning: if statement has empty body [-Wempty-body]|
|10|note: put the semicolon on a separate line to silence this warning|
13|error: expected expression|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

推荐答案

开始于查看你的代码和错误消息 - 它们非常好。

Start by looking at your code, and the errors messages - they are pretty good.
|10|warning: if statement has empty body [-Wempty-body]|
|10|note: put the semicolon on a separate line to silence this warning|



| 10 |位表示:源文件,第10行。即,问题出现在这一行:


The |10| bits means: "Source file, line 10". I.e, the problem is on this line:

if (ave<60);

果然,你的 if 条件以分号结束,所以它以该行结束。就像你写的那样:

And sure enough, your if condition ends with a semicolon, so it ends on that line. It's like you wrote:

if (ave<60) DoNothing();
printf("Failed");

printf语句将永远执行。

另一个错误是假的,由第一个引起 - 它无法找到匹配的 if 语句 else 因为你的分号会提前终止 if



检查你的 #include - 它们没有在这里显示(或在你发布的文本中),但我猜他们有< io.h>或者与他们相似。



请不要将问题标记为错误 - 至少使用C语言 - 只有那些知道语言,可以帮助你阅读。

The "printf" statement will always be executed.
The other error is spurious, and caused by the first - it can't find a matching if statement for the else because your semicolon terminates the if early.

Check your #includes as well - they don't show here (or in the text you posted) but I'd guess they have <io.h> or similar with them.

And please, don't tag questions as "Errors" - use the language at least "C" - that way only people who know the language and can help you will read it.


13行怎么样?我不明白。

谢谢你的回复。
what about the 13 line ?I dont understand that.
thank you for the reply.


这篇关于平均标记错误,begginer CODEBLOCKS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆