Here's the thing... I wanted to do a sine wave and i did it, however i want to put a * at each turning point.. i can't seem to find an equation for it with using if. Also, i want to use / if the waveform is falling and \ if it is rising.
I get that but the problem is that the * keeps popping up everywhere instead of just one place! I tried so many equations but the * just wont go where it belongs. and if i run the program with the if included then its not gonna work like i how i want it to be.
I really can't guess what is wrong.
#include <cmath>
...
int ch;
deriv = cos(angle);
if (fabs(sinVal) < 0.001) ch = '0'; // pick an appropriate tolerance
elseif (cosVal < 0) ch = '/;
else ch = '\\';
putchar(ch); // faster than printf
To really get the spot where it crosses zero you need to pick that tolerance carefully. It must be big enough to catch the change but small enough that that you don't get two positions showing it.
ok...I did as 'kemort' suggested and it looked REALLY good right now!
except that...at the turning point there is still a \ and / next to my *
how do i get rid of it?
If cosVal would be exactly 0 (and numSpaces 0 or 60), then you would print all three ( *, /, \ ).
You did use else for something before. Not all of that was bad.
Note. You could do without cos:
If current is larger than previous, then current is either rising or at peak.
If current is smaller than previous, then current is either falling or at bottom.
If current and previous are equal, then you have flat.
In order to check these cases, you have to know previous, current, and next value.