| | |
error when compiling murphy's law with gcc
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
C Syntax (Toggle Plain Text)
// Calcolo formula per Legge di Murphy (<a rel="nofollow" class="t" href="http://www.andreagozzi.com" target="_blank">www.andreagozzi.com</a>) // Inclusione librerie in directory di sistema #include <math.h> #include <stdio.h> #include <string.h> // Funzione Main() main() { // Dichiarazione delle variabili float urgenza; float complessita; float abilita; float frequenza; float importanza; float e; // Impostazione variabile e fissata al valore 0.7 e = 0.7; float risultato; float pigreco; // Impostazione variabile pigreco fissata al valore 3.14 pigreco = 3.14159265358979; // Stampa header printf("Calcolo Riuscita Operazione Seguendo Legge Di Murphy\n\n"); printf("Impostare valore URGENZA [compreso tra 0 e 9]: "); scanf("%c", &urgenza); printf("Imostare valore COMPLESSITA [compreso tra 0 e 9]: "); scanf("%c", &complessita); printf("Imostare valore ABILITA [compreso tra 0 e 9]: "); scanf("%c", &abilita); printf("Imostare valore FREQUENZA [compreso tra 0 e 9]: "); scanf("%c", &frequenza); printf("Imostare valore IMPORTANZA [compreso tra 0 e 9]: "); scanf("%c", &importanza); risultato = ((((urgenza+complessita+importanza)*(10-abilita))/20)*(e)*((1)/((1-(sin((frequenza/10))))*pigreco))); printf("Risultato: %C\n", risultato); if(risultato < 4.4) printf("OK.Valore dell'equazione di Murphy basso, puoi procedere.\n"); else printf("Occhio rischi la stangata.Il valore e alto, sarai sfigato!\n"); }
this is the coding for a basic script calculating murphy's law :cheesy: based on this equation.
when trying to compile it this is the output given by gcc:
confuser@hybrid:~/Programmazione$ gcc murphy_v1.c -o murphy_v1
murphy_v1.c:39:2: warning: no newline at end of file
/tmp/cc06N55O.o(.text+0x11c): In function `main':
: undefined reference to `sin'
collect2: ld returned 1 exit status
i've been searching alot on the web for solutions but i couldnt find any
>warning: no newline at end of file
Go to the end of the file and hit enter. Save and recompile.
>undefined reference to `sin'
Did you link to the math library?
Go to the end of the file and hit enter. Save and recompile.
>undefined reference to `sin'
Did you link to the math library?
C Syntax (Toggle Plain Text)
gcc src.c -lm
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
>warning: no newline at end of file
Go to the end of the file and hit enter. Save and recompile.
•
•
•
•
>undefined reference to `sin'
Did you link to the math library?
C Syntax (Toggle Plain Text)
gcc src.c -lm
>the link is (#include <math.h>) ok
math.h is the header that contains declarations. Did you link to the math library that has object code as I gave an example for? If not then the next question is moot because your code will never compile.
>somebody says the output is in radiants while other say in decimal numbers
...You're confused. There are two potential representations for the value returned by sin, radians and degrees. sin as defined by the standard returns radians and it's trivial to convert radians to degrees, just multiply by 180 / pi. As for decimal numbers, I assume you mean floating-point, which is the type that sin returns.
math.h is the header that contains declarations. Did you link to the math library that has object code as I gave an example for? If not then the next question is moot because your code will never compile.
>somebody says the output is in radiants while other say in decimal numbers
...You're confused. There are two potential representations for the value returned by sin, radians and degrees. sin as defined by the standard returns radians and it's trivial to convert radians to degrees, just multiply by 180 / pi. As for decimal numbers, I assume you mean floating-point, which is the type that sin returns.
I'm here to prove you wrong.
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
...You're confused. There are two potential representations for the value returned by sin, radians and degrees. sin as defined by the standard returns radians and it's trivial to convert radians to degrees, just multiply by 180 / pi. As for decimal numbers, I assume you mean floating-point, which is the type that sin returns.
sin doesn't return any angle, neither radiants nor degrees.
sin takes radiants as its parameter and returns a value in the range of -1 .. +1;
K.
>I think your'e confused.
For some reason I kept typing return when I meant compute. I have no excuse.
And please use the correct terminology, I hate to be corrected by someone who says radiants when they mean radians. It just makes me feel even dumber to be corrected by someone totally clueless.
For some reason I kept typing return when I meant compute. I have no excuse.
And please use the correct terminology, I hate to be corrected by someone who says radiants when they mean radians. It just makes me feel even dumber to be corrected by someone totally clueless.
I'm here to prove you wrong.
![]() |
Other Threads in the C Forum
- Previous Thread: help me with c program please
- Next Thread: Im completely lost on this one
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






