Thread: Well-done, but can't compile

  1. #1
    Registered User
    Join Date
    Aug 2017
    Posts
    21

    Well-done, but can't compile

    Hello gentle folks
    I got this code
    Code:
    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    
    int main(void)
    {
    	float a, b, c;
    	float delta;
    	float x1, x2;
    	
    	printf("Risoluzione equazioni di secondo grado\n");
    	printf("Equazione nella forma ax^2+bx+c=0\n");
    	
    	printf("Immetti il coefficiente a: \n");
    	scanf("%f", &a);
    	printf("Immetti il coefficiente b: \n");
    	scanf("%f", &b);
    	printf("Immetti il coefficiente c: \n");
    	scanf("%f", &c);
    	if ( a == 0 )
    	{
    		if ( b != 0 )
    		{
    			x1 = -c / b;
    			printf("Una soluzione:x=%f\n", x1);
    		}
    		else
    		{
    			if ( b == 0 )
    			{
    				printf("Equazione indeterminata: ammette infinite soluzioni\n");
    			}
    		    else
    		    {
    				printf("Equazione impossibile\n");
    			}
    		}
    	}
    	else
    	{
    		delta = b*b - (4*a*c);
    		printf("Il discriminante vale: %f \n", delta);
    		if ( delta < 0 )
    		{
    			printf("Non ci sono soluzioni in campo reale\n");
    		}
    		else if ( delta == 0 )
    		{
    			x1 = -b / (2*a) ;
    			printf("Una soluzione doppia: x=%f \n", x1);
    		}
    		else
    		{
    			x1 = ( -b - sqrt(delta) ) / ( 2 * a );
    			x2 = ( -b + sqrt(delta) ) / ( 2 * a );
    		    printf("Due soluzioni x:%f e %f \n", x1, x2);
    		}
    	}
    	
    	exit(0);
    }
    No mistakes, but i can't compile due to this warnings:
    Well-done, but can't compile-schermata-2018-10-24-17-27-42-png
    Can someone help me to understand?

  2. #2
    Guest
    Guest
    Hello Alcatraz, my guess is that you have to link against the C math library to get the implementations of the functions in the math.h header. This seems to be a quirk in C.

    So simply try adding -lm (a small L) to your compiler flags and see if that fixes it.

  3. #3
    Registered User
    Join Date
    Aug 2017
    Posts
    21
    Well-done, but can't compile-schermata-2018-10-24-18-16-45-png
    I tried,same error
    If I try with "compile object" it tells me compilation well done but no file .exe is generated

  4. #4
    Guest
    Guest
    What are "%e" and "%f"?

    Only add -lm at the end of Build, after "%f", and nowhere else and see if that works.

  5. #5
    Guest
    Guest
    Also, your IDE might offer a better way for adding libraries, please read the documentation on that.

  6. #6
    Registered User
    Join Date
    Aug 2017
    Posts
    21
    ->Which documentation do you mean? The IDE's one?
    ->"%e" and "%f" are standard, I didn't add those

  7. #7
    Registered User
    Join Date
    Aug 2017
    Posts
    21
    It works now If i build btw. Thanks
    If I press "compile everything" compiler tells me : "make: *** No targets specified and no makefile found. Stop."
    If I press "compile object" compiler tells me: make: 'Esercizio-n11x.o' is up to date.

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    If I press "compile everything" compiler tells me : "make: *** No targets specified and no makefile found. Stop."
    You might want to read your IDE documentation in case your setup uses a default makefile and target.

    The way that make works is "make -f <makefile> <target>" when specifying a file and target, or "make <target>" when you have a default makefile. make automatically tries to read files with variations of the name "makefile". Here is a page with some quick instructions: ftp://ftp.gnu.org/old-gnu/Manuals/ma...er/make_9.html

    If I press "compile object" compiler tells me: make: 'Esercizio-n11x.o' is up to date.
    This is usually good, it means that you've made no changes since your last compile, so the compiler has nothing to do.

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    As a side note, because 'a' 'b' and 'c' are floats, you should do the following...

    Code:
    if (a == 0.0)
    {
       ...
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile???
    By BestGameMovie in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2005, 08:25 PM
  2. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM
  3. Replies: 3
    Last Post: 03-07-2003, 09:06 PM
  4. Won't compile, can YOU compile it on your compiler?
    By incognito in forum C++ Programming
    Replies: 12
    Last Post: 03-10-2002, 12:00 PM

Tags for this Thread