Hello!
From the code you are posting, you have 2 values initialized to 0.
Therefore first of all, the following line:
fMinModulation + (i*fDeltaModulation)
will translate to
0 + i * 0
which is not much.
That said, the runtime should blow up at the next line, because 1/temp
consequently translates to 1/0.
Is this your real code? Or are the snippets taken from 2 parts in the program,
and in between, temp is initialized to some non-zero values?
Supposing it's the case and all your temp values are non-zero: you
are using integer values, and therefore you are performing integer division.
This means that for any temp which is more than 1, the terme 1/temp will be
less than 0.5 which yields 0 in integer values.
But if you calculate 1000000/temp instead, you will get non-zero values.
Now beside this, your code is not safe. You should always test when you do a
division. What do you want to do if temp = 0?
something like:
Code C++ - [expand] |
1
2
3
4
5
6
| if(temp > 0) {
tempPeriod = 1000000/temp;
}
else {
// Write your B plan here.
} |
Dora.