Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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)) ===|
Posted

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|

The |10| bits means: "Source file, line 10". I.e, the problem is on this line:
C++
if (ave<60);
And sure enough, your if condition ends with a semicolon, so it ends on that line. It's like you wrote:
C++
if (ave<60) DoNothing();
printf("Failed");
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.
 
Share this answer
 
what about the 13 line ?I dont understand that.
thank you for the reply.
 
Share this answer
 
Comments
Matt T Heffron 9-Nov-15 19:20pm    
Don't reply to OriginalGriff's solution with a new Solution. He won't see it unless he happens to look here again. Use the "Have a Question of Comment?" button to reply to a Solution. (If a "conversation" starts with the comments, use the "Reply" button for the comment you want to reply to.)
These will send an email notification to the person to whom you are replying and then they can continue to help you.

Now, the |13| error is the one that OriginalGriff referred to as "other error is spurious". When you fix the semicolon problem it should go away.
asus12 10-Nov-15 12:51pm    
thank you for your reply about the question.
Also,i am new here so im sorry for the mess.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900