User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 391,774 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 2759 | Replies: 13
Reply
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation: trashed is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
trashed trashed is offline Offline
Newbie Poster

error when compiling murphy's law with gcc

  #1  
Oct 13th, 2004
// Calcolo formula per Legge di Murphy (www.andreagozzi.com)
// 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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: error when compiling murphy's law with gcc

  #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?
gcc src.c -lm
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation: trashed is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
trashed trashed is offline Offline
Newbie Poster

Re: error when compiling murphy's law with gcc

  #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?
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  
Join Date: Apr 2004
Location: Dhaka, Bangladesh
Posts: 344
Reputation: Asif_NSU is on a distinguished road 
Rep Power: 5
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

  #4  
Oct 13th, 2004
From my experience in Turbo C++ sin() function returns radian values.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: error when compiling murphy's law with gcc

  #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.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Oct 2004
Location: Austria
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

  #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  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: error when compiling murphy's law with gcc

  #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.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Oct 2004
Location: Austria
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

  #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  
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation: trashed is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
trashed trashed is offline Offline
Newbie Poster

Re: error when compiling murphy's law with gcc

  #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  
Join Date: Oct 2004
Location: Austria
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: error when compiling murphy's law with gcc

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Other Threads in the C Forum

All times are GMT -4. The time now is 4:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC