•
•
•
•
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
![]() |
•
•
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation:
Rep Power: 4
Solved Threads: 0
// 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
>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?
gcc src.c -lm
Member of: Beautiful Code Club.
•
•
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation:
Rep Power: 4
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?
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
•
•
Join Date: Apr 2004
Location: Dhaka, Bangladesh
Posts: 344
Reputation:
Rep Power: 5
Solved Threads: 3
>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.
Member of: Beautiful Code Club.
•
•
Join Date: Oct 2004
Location: Austria
Posts: 29
Reputation:
Rep Power: 4
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.
Member of: Beautiful Code Club.
•
•
Join Date: Oct 2004
Location: Modena, Italy
Posts: 21
Reputation:
Rep Power: 4
Solved Threads: 0
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
- Previous Thread: help me with c program please
- Next Thread: Im completely lost on this one



Linear Mode