|
|
Syntex error, bit i dont see why
#350234
12/14/10 18:50
12/14/10 18:50
|
Joined: Sep 2010
Posts: 82
peteredlin
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 82
|
The following code gives an syntex error;
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
var Drijfstang_l = 1;
var Fdrijfstang;
var draaihoek;
var alfa;
var fliegwiel_r;
var gamma;
var Fzuiger = 10;
var Ffliegwiel;
SOUND* dieselhit = "singledieselhit.wav";
PANEL* panDisplay =
{
digits(35, 10, "draaihoek = %0.f", *, 1, draaihoek);
flags = VISIBLE;
}
function hoeksnelheid()
{
if (draaihoek != 0 || draaihoek != 180)
{
alfa = asinv (Drijfstang_l / sinv( draaihoek * fliegwiel_r ));
}
else
{
alfa = 0;
}
gamma = 180 - alfa - draaihoek;
Fdrijfstang = cosv(alfa) * Fzuiger;
Ffliegwiel = sinv(gamma) * Fdrijfstang;
}
function main()
{
hoeksnelheid();
}
I dont see why..
Last edited by peteredlin; 12/14/10 19:01.
|
|
|
Re: Syntex error, bit i dont see why
[Re: peteredlin]
#350242
12/14/10 19:14
12/14/10 19:14
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
if (draaihoek != 0 || draaihoek != 180)
Is bad -- you're saying "If draaihoek is not zero, or draaihoek is not 180" -- since "draaihoek" can never be 0 and 180 at the same time, it'll always be true. I think what you mean is:
if (draaihoek != 0 && draaihoek != 180)
But even then, what if draaihoek is 360? or -180? And fliegwiel_r modifies the value anyway, so you still have a potential divide by zero. So really, it should be:
if (sinv( draaihoek * fliegwiel_r ) != 0)
Assuming the sole purpose of the if/else is to prevent a divide by zero. Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|