View previous topic :: View next topic |
Author |
Message |
thanhhavdt
Joined: 09 Oct 2006 Posts: 12 Location: hoangsam
|
Help me why function not return exactly value |
Posted: Tue Apr 16, 2024 10:45 am |
|
|
Help me why function not return exactly value
Last edited by thanhhavdt on Mon May 06, 2024 9:32 am; edited 1 time in total |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Apr 16, 2024 12:14 pm |
|
|
Your comment and function do not match.
Quote: | Data_DKX = (((400*a)+(40*(b+45))+(4*c)+d)); //Data_DKX = ((10000*a)+(1000*(b+45))+(100*c)+d)/25; |
If the part in the commented section is correct, then it appears you divided each constant by 25 except for the constant of 1 for d. |
|
|
thanhhavdt
Joined: 09 Oct 2006 Posts: 12 Location: hoangsam
|
|
Posted: Wed Apr 17, 2024 7:18 am |
|
|
gaugeguy wrote: | Your comment and function do not match.
Quote: | Data_DKX = (((400*a)+(40*(b+45))+(4*c)+d)); //Data_DKX = ((10000*a)+(1000*(b+45))+(100*c)+d)/25; |
If the part in the commented section is correct, then it appears you divided each constant by 25 except for the constant of 1 for d. |
Sorry, comment is:
Data_DKX = (((400*a)+(40*(b+45))+(4*c)+d)); //Data_DKX = (((10000*a)+(1000*(b+45))+(100*c))/25)+d;
and Data_DKX = ((((400*a)+(40*(b))+(4*c)+d))-1800); //Data_DKX = (((10000*a)+(1000*(b-45))+(100*c))/25)+d; |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Apr 17, 2024 9:09 am |
|
|
It'd be easier to see your error if you break down the equation !
ie
answer=first math term 'a'
answer =answer + 2nd math term 'b'
answer =answer + 3rd math term 'c'
answer=answer + 4th math term 'd'
Having it in one long line of code can be very confusing and hard to read.
Now once you have the correct code, you could reduce to one line.
Also put comments at the end of lines of code. Old habit from assembler days but it really,really helps and cost you nothing. Handy for when you ask 'is this right ?' or 3 days later when you ask yourself WHY did I code this mess ?? |
|
|
thanhhavdt
Joined: 09 Oct 2006 Posts: 12 Location: hoangsam
|
|
Posted: Wed Apr 17, 2024 6:12 pm |
|
|
In read_Data_DKX_song_met(), Data_DKX= 10000; 10002; ....13400
but in read_Data_DKX_song_deximet(), Data_DKX= 10001; 10002; ....13999
function read_Data_DKX_song_deximet() return exactly value with even number (Data_DKX= 10000; 10002; ....) but not with odd number (Data_DKX= 10001; 10003; ....). Please heplme |
|
|
|