B
Bill Cunningham
I thought I would submit this function I wrote to the group for opinions
on style. The function itself seems to work. I know sometimes not returning
anything can lead to undefined behavior but with main returning int I
believe int is considered by the standard as the default type. So the return
0 in main isn't necessary but the returns in t_range are. t_range means true
range between security prices. Any opinions on how I can improve this
function as far as style?
#include <stdio.h>
double t_range(double hi, double low, double pc)
{
double ans1, ans2, ans3;
ans1 = ans2 = ans3 = 0.0;
ans1 = hi - low;
ans2 = pc - low;
ans3 = hi - pc;
if (ans1 > ans2 && ans1 > ans3)
return ans1;
else if (ans2 > ans3 && ans2 > ans1)
return ans2;
else if (ans3 > ans2 && ans3 > ans1)
return ans3;
else {
return -1;
}
}
int main(void)
{
double r;
r = t_range(1.25, 1.37, .67);
printf("%.2f\n", r);
return 0;
}
http://www.incrediblecharts.com/indicators/true_range.php
B
on style. The function itself seems to work. I know sometimes not returning
anything can lead to undefined behavior but with main returning int I
believe int is considered by the standard as the default type. So the return
0 in main isn't necessary but the returns in t_range are. t_range means true
range between security prices. Any opinions on how I can improve this
function as far as style?
#include <stdio.h>
double t_range(double hi, double low, double pc)
{
double ans1, ans2, ans3;
ans1 = ans2 = ans3 = 0.0;
ans1 = hi - low;
ans2 = pc - low;
ans3 = hi - pc;
if (ans1 > ans2 && ans1 > ans3)
return ans1;
else if (ans2 > ans3 && ans2 > ans1)
return ans2;
else if (ans3 > ans2 && ans3 > ans1)
return ans3;
else {
return -1;
}
}
int main(void)
{
double r;
r = t_range(1.25, 1.37, .67);
printf("%.2f\n", r);
return 0;
}
http://www.incrediblecharts.com/indicators/true_range.php
B