// Calcolo formula per Legge di Murphy ([url]www.andreagozzi.com[/url])
// 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

Recommended Answers

All 13 Replies

>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

>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

From my experience in Turbo C++ sin() function returns radian values.

>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.

...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.

commented: Even though that was just a slip of mind--thanx for correcting --Asif_NSU +1

>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.

but sin doesn't compute an angle. does it ? maybe you should feel the way you feel. I wander who is clueless here.
K

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?

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.

thanks alot the sinus problem is solved now.
this is the final code:

// 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");
// Richiede inserimento valori per ogni variabile
	printf("Impostare valore URGENZA [compreso tra 0 e 9]: \n");
	scanf("%c", &urgenza);
	printf("Impostare valore COMPLESSITA [compreso tra 0 e 9]: \n");
	scanf("%c", &complessita);
	printf("Impostare valore ABILITA [compreso tra 0 e 9]: \n");
	scanf("%c", &abilita);
	printf("Impostare valore FREQUENZA [compreso tra 0 e 9]: \n");
	scanf("%c", &frequenza);
	printf("Impostare valore IMPORTANZA [compreso tra 0 e 9]: \n");
	scanf("%c", &importanza);
// Calcola valore complessivo equazione
	risultato = ((((urgenza+complessita+importanza)*(10.0-abilita))/20.0)*(e)*((1.0)/(1.0-sin((frequenza*pigreco/180)/10.0)));
// Stampa risultato dell'equazione
	printf("Risultato: %C\n", risultato);
// Inserisce il commento in base al valore del 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");
}

that gives this output :sad: and i dont really know what to do:

murphy_v1.c: In function `main':
murphy_v1.c:36: error: parse error before ';' token

sorry but im really a newbie, i started C lessons last week

I have modified your code a little.

// 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("%f", &urgenza);
	printf("\nImostare valore COMPLESSITA [compreso tra 0 e 9]: ");
	scanf("%f", &complessita);
	printf("\nImostare valore ABILITA [compreso tra 0 e 9]: ");
	scanf("%f", &abilita);
	printf("\nImostare valore FREQUENZA [compreso tra 0 e 9]: ");
	scanf("%f", &frequenza);
	printf("\nImostare valore IMPORTANZA [compreso tra 0 e 9]: ");
	scanf("%f", &importanza);
	risultato = ((((urgenza+complessita+importanza)*(10-abilita))/20)*(e)*((1)/((1-(sin((frequenza/10))))*pigreco)));
	printf("\nRisultato: %C\n", risultato);
	if(risultato < 4.4) printf("OK.Valore dell'equazione di Murphy basso, puoi procedere.\n");
	else
	printf("\nOcchio rischi la stangata.Il valore e alto, sarai sfigato!\n");
}

if you compile like this

gcc  murphy_v1.c -o murphy_v1 -lm

it should work.
K.

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.

errr... sorry i forgot that sin() functions return value must be between -1 and 1 inclusive. What I should have said is that sin() takes a double as it's argument but takes it as if it is in radian not in degree. Yeah... i guess that's what i should have said.
Thanx for correcting Zuk.

god bless you it works perfectly now!
grazie mille :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.