error when compiling murphy's law with gcc

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 29
Reputation: trashed is an unknown quantity at this point 
Solved Threads: 0
trashed trashed is offline Offline
Light Poster

error when compiling murphy's law with gcc

 
1
  #1
Oct 13th, 2004
  1. // Calcolo formula per Legge di Murphy (<a rel="nofollow" class="t" 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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,752
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error when compiling murphy's law with gcc

 
1
  #2
Oct 13th, 2004
>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
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: trashed is an unknown quantity at this point 
Solved Threads: 0
trashed trashed is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

 
0
  #3
Oct 13th, 2004
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
>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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: error when compiling murphy's law with gcc

 
0
  #4
Oct 13th, 2004
From my experience in Turbo C++ sin() function returns radian values.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,752
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error when compiling murphy's law with gcc

 
0
  #5
Oct 13th, 2004
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

 
1
  #6
Oct 14th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,752
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error when compiling murphy's law with gcc

 
0
  #7
Oct 14th, 2004
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

 
0
  #8
Oct 14th, 2004
but sin doesn't compute an angle. does it ? maybe you should feel the way you feel. I wander who is clueless here.
K
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: trashed is an unknown quantity at this point 
Solved Threads: 0
trashed trashed is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

 
0
  #9
Oct 14th, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

 
0
  #10
Oct 14th, 2004
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC