Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse shows wrong output(I have written a c program to find area of triangle using 3 sides.The program works fine on codechef.com's c compiler but it gives 0.00000 or -1#INDEF output in eclipse Mars2 with MinGW compiler.)
icon1.gif  Eclipse shows wrong output [message #1738784] Sun, 24 July 2016 06:16 Go to next message
Eclipse UserFriend
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void fpage45(){
int s1,s2,s3;
float area,s;
puts("Enter the sides of triangle");
fflush(stdout);
scanf("%d%d%d",&s1,&s2,&s3);
s=(s1+s2+s3)/2;
area=sqrt(s*(s-s1)*(s-s2)*(s-s3));
printf("Area of triangle=%f",area);
}
int main(void) {
fpage45();
return EXIT_SUCCESS;
}

Console:
Enter the sides of triangle
10
20
30
Area of triangle=0.000000
Re: Eclipse shows wrong output [message #1738786 is a reply to message #1738784] Sun, 24 July 2016 08:01 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

This is not Eclipse showing the wrong output, but rather a bug in your program. As this help forum is for using the Eclipse C/C++ Development tools, the best I can recommend is to look up some C tutorials and user groups for some help.

In the meantime, try running your program in the debugger in Eclipse and stepping through each line to see which variables have the value you do or do not expect. If you need further help on using the Eclipse C/C++ Development Tools I look forward to your questions.

Jonah
Re: Eclipse shows wrong output [message #1738789 is a reply to message #1738786] Sun, 24 July 2016 10:21 Go to previous messageGo to next message
Eclipse UserFriend
Your program is OK. You can't make a 10 / 20 / 30 triangle. Give a go at drawing one. I doubt that it worked with the same inputs using another compiler. Try a = 4, b = 13 and c = 15 with area =24 instead.

In any case, Eclipse is just an editor that can cause the execution of things like the compiler and linker. Understand these are tools separate from Eclipse. You should make an effort to understand what your tools do for you and avoid treating them as black boxes.

The same for your programs. There's an old adage: Garbage In; Garbage Out. Believe it.


Re: Eclipse shows wrong output [message #1738790 is a reply to message #1738789] Sun, 24 July 2016 10:40 Go to previous message
Eclipse UserFriend
@David, Good catch on the input problem!
Previous Topic:files in the project does not get compiled
Next Topic:Neon version CDT errors (library and even simple functions)
Goto Forum:
  


Current Time: Fri Nov 07 14:16:59 EST 2025

Powered by FUDForum. Page generated in 0.03206 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top