943,505 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4532
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 13th, 2004
1

error when compiling murphy's law with gcc

Expand Post »
  1. // Calcolo formula per Legge di Murphy (<a rel="nofollow" href="http://www.andreagozzi.com" target="_blank">www.andreagozzi.com</a>)
  2. // Inclusione librerie in directory di sistema
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. // Funzione Main()
  7. main()
  8. {
  9. // Dichiarazione delle variabili
  10. float urgenza;
  11. float complessita;
  12. float abilita;
  13. float frequenza;
  14. float importanza;
  15. float e;
  16. // Impostazione variabile e fissata al valore 0.7
  17. e = 0.7;
  18. float risultato;
  19. float pigreco;
  20. // Impostazione variabile pigreco fissata al valore 3.14
  21. pigreco = 3.14159265358979;
  22. // Stampa header
  23. printf("Calcolo Riuscita Operazione Seguendo Legge Di Murphy\n\n");
  24. printf("Impostare valore URGENZA [compreso tra 0 e 9]: ");
  25. scanf("%c", &urgenza);
  26. printf("Imostare valore COMPLESSITA [compreso tra 0 e 9]: ");
  27. scanf("%c", &complessita);
  28. printf("Imostare valore ABILITA [compreso tra 0 e 9]: ");
  29. scanf("%c", &abilita);
  30. printf("Imostare valore FREQUENZA [compreso tra 0 e 9]: ");
  31. scanf("%c", &frequenza);
  32. printf("Imostare valore IMPORTANZA [compreso tra 0 e 9]: ");
  33. scanf("%c", &importanza);
  34. risultato = ((((urgenza+complessita+importanza)*(10-abilita))/20)*(e)*((1)/((1-(sin((frequenza/10))))*pigreco)));
  35. printf("Risultato: %C\n", risultato);
  36. if(risultato < 4.4) printf("OK.Valore dell'equazione di Murphy basso, puoi procedere.\n");
  37. else
  38. printf("Occhio rischi la stangata.Il valore e alto, sarai sfigato!\n");
  39. }

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
Reputation Points: 11
Solved Threads: 0
Light Poster
trashed is offline Offline
30 posts
since Oct 2004
Oct 13th, 2004
1

Re: error when compiling murphy's law with gcc

>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?
  1. gcc src.c -lm
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 13th, 2004
0

Re: error when compiling murphy's law with gcc

Quote originally posted by Narue ...
>warning: no newline at end of file
Go to the end of the file and hit enter. Save and recompile.
ok i did that.thanks
Quote ...
>undefined reference to `sin'
Did you link to the math library?
  1. gcc src.c -lm
the link is (#include <math.h>) ok but i'm not sure about the sin() function because somebody says the output is in radiants while other say in decimal numbers
Reputation Points: 11
Solved Threads: 0
Light Poster
trashed is offline Offline
30 posts
since Oct 2004
Oct 13th, 2004
0

Re: error when compiling murphy's law with gcc

From my experience in Turbo C++ sin() function returns radian values.
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Oct 13th, 2004
0

Re: error when compiling murphy's law with gcc

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 14th, 2004
1

Re: error when compiling murphy's law with gcc

Quote 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.
I think your'e confused.
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.
ZuK
Reputation Points: 11
Solved Threads: 0
Light Poster
ZuK is offline Offline
29 posts
since Oct 2004
Oct 14th, 2004
0

Re: error when compiling murphy's law with gcc

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 14th, 2004
0

Re: error when compiling murphy's law with gcc

but sin doesn't compute an angle. does it ? maybe you should feel the way you feel. I wander who is clueless here.
K
ZuK
Reputation Points: 11
Solved Threads: 0
Light Poster
ZuK is offline Offline
29 posts
since Oct 2004
Oct 14th, 2004
0

Re: error when compiling murphy's law with gcc

i am confused now, that's sure...
so then if i want to get a decimal result of (1-sin((x/10)) what do i have to do considering x is a number between 0.00 and 9.00?
Reputation Points: 11
Solved Threads: 0
Light Poster
trashed is offline Offline
30 posts
since Oct 2004
Oct 14th, 2004
0

Re: error when compiling murphy's law with gcc

I guess in your example x is an angle of 9.0 degrees.
so you have to write
result = 1-sin((x*3.1415926/180)/10.0);
K.
ZuK
Reputation Points: 11
Solved Threads: 0
Light Poster
ZuK is offline Offline
29 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: help me with c program please
Next Thread in C Forum Timeline: Im completely lost on this one





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC