平均真实范围 [英] average true range
问题描述
我已经创建了这两个文件。称为main.c和atr.c.他们似乎很好地工作了
。我只是想提交它们,看看有什么错误,其他人知道更多可能会发现的错误。谢谢。
atr.c
#include< stdio.h>
double
atr(双倍,双倍,双倍)
{
if(th - tl th - wc&& tl - wc< th - tl)
{
返回tht |
}
if(th - wc th - tl& tl - wc< th - wc)
{
return th - wc;
}
if(tl - wc th - wc&& th - tl< tl - wc)
{
return tl - wc; < br $>
}
}
main.c
#include < stdio.h>
#include< stdlib.h>
extern double atr(double th,double tl,double wc);
int
main(int argc,char * argv [])
{
if(argc != 4)
{
fprintf(stderr,使用错误th,tl,wc \ n);
退出( EXIT_FAILURE);
}
double th,tl,wc;
th = strtod(arg v [1],NULL);
tl = strtod(argv [2],NULL);
wc = strtod(argv [3],NULL);
printf("%。2f \ n",atr(th,tl,wc));
}
比尔
哦,是的,tl意味着今天的低价。这意味着今天很高,wc意味着周'
关闭。
比尔
< blockquote> 6月11日,11:11 * am,Bill Cunningham < nos ... @ nspam.comwrote:
* *我创建了这两个文件。称为main.c和atr.c.他们看起来好像很好。我只是想提交它们,看看有什么错误,其他人知道更多可能会发现的错误。谢谢。
atr.c
#include< stdio.h>
double
atr(双倍,双倍,双倍)
{
* if(th - tl th - wc&& tl - wc< th - tl)
* * {
* * *返回th-tl;
* *}
* if(th - wc th - tl&& tl - wc< th - wc)
* * {
* * *返回 - wc;
* *}
* if(tl - wc th - wc&& th - tl< tl - wc)
* * {
* * *返回tl - wc;
* *}
}
< br $>
main.c
#include< stdio.h>
#include< stdlib.h>
extern double atr(double th,double tl,double wc);
int
main(int argc,char * argv [])
{
* if(argc!= 4)
* * {
* * * fprintf(stderr,使用错误th,tl,wc \ n);
* * *退出(EXIT_FAILURE);
* *}
* double th,tl,wc;
* th = strtod(argv [1],NULL);
* tl = strtod(argv [2],NULL);
* wc = strtod(argv [3],NULL);
* printf("%。2f \ n" ;,atr(th,tl,wc));
}
你还没有说出意图是什么atr函数是什么,那么我们怎么知道它是否得到正确答案?
只是一些数学表明有更清洁比较。
例如,
if(th - tl th - wc)
与
相同
if(wc tl)
-
Fred Kleinschmidt
On Jun 11,11:11 * am,Bill Cunningham < nos ... @ nspam.comwrote:
* *我创建了这两个文件。称为main.c和atr.c.他们看起来好像很好。我只是想提交它们,看看有什么错误,其他人知道更多可能会发现的错误。谢谢。
atr.c
#include< stdio.h>
double
atr(双倍,双倍,双倍)
{
* if(th - tl th - wc&& tl - wc< th - tl)
* * {
* * *返回th-tl;
* *}
* if(th - wc th - tl&& tl - wc< th - wc)
* * {
* * *返回 - wc;
* *}
* if(tl - wc th - wc&& th - tl< tl - wc)
* * {
* * *返回tl - wc;
* *}
}
< br $>
main.c
#include< stdio.h>
#include< stdlib.h>
extern double atr(double th,double tl,double wc);
int
main(int argc,char * argv [])
{
* if(argc!= 4)
* * {
* * * fprintf(stderr,使用错误th,tl,wc \ n);
* * *退出(EXIT_FAILURE);
* *}
* double th,tl,wc;
* th = strtod(argv [1],NULL);
* tl = strtod(argv [2],NULL);
* wc = strtod(argv [3],NULL);
* printf("%。2f \ n" ;,atr(th,tl,wc));
}
修复了一些更明显的错误,我会尝试这个:
#include< math.h>
#include< stdio.h>
#include< stdlib.h>
#include< assert.h>
静态双atr(双th,双tl,双wc)
{
if(th - tl th - wc&& tl-wc< th - tl){
返回th - tl;
}
if(th - wc th - tl&& tl - wc < th - wc){
返回th - wc;
}
if(tl - wc th - wc&& th - tl< tl - wc){
返回tl - wc;
}
断言(0);
返回sqrt(-1。);
}
int main(int argc,char * argv [])
{
加倍,
tl,
wc;
if(argc!= 4){
fprintf(stderr,用法错误th,tl,wc \ n);
退出(EXIT_FAILURE);
}
th = strtod(argv [1],NULL);
tl = strtod(argv [2],NULL);
wc = strtod(argv [3] ,NULL);
printf("%。2f \ n",atr(th,tl,wc));
返回0;
}
然后给它输入20 20 20并看看会发生什么。
I have create these 2 files. Called main.c and atr.c. They seem to work
pretty well. I just wanted to submit them to see what if any errors others
that know more might find. Thanks.
atr.c
#include <stdio.h>
double
atr (double th, double tl, double wc)
{
if (th - tl th - wc && tl - wc < th - tl)
{
return th - tl;
}
if (th - wc th - tl && tl - wc < th - wc)
{
return th - wc;
}
if (tl - wc th - wc && th - tl < tl - wc)
{
return tl - wc;
}
}
main.c
#include <stdio.h>
#include <stdlib.h>
extern double atr ( double th, double tl, double wc );
int
main (int argc, char *argv[])
{
if (argc != 4)
{
fprintf (stderr, "usage error th, tl, wc\n");
exit (EXIT_FAILURE);
}
double th, tl, wc;
th = strtod (argv[1], NULL);
tl = strtod (argv[2], NULL);
wc = strtod (argv[3], NULL);
printf("%.2f\n", atr(th, tl, wc));
}
Bill
Oh yes and tl means today''s low. Th means today''s high and wc means week''s
close.
Bill
On Jun 11, 11:11*am, "Bill Cunningham" <nos...@nspam.comwrote:* * I have create these 2 files. Called main.c and atr.c. They seem towork
pretty well. I just wanted to submit them to see what if any errors others
that know more might find. Thanks.
atr.c
#include <stdio.h>
double
atr (double th, double tl, double wc)
{
* if (th - tl th - wc && tl - wc < th - tl)
* * {
* * * return th - tl;
* * }
* if (th - wc th - tl && tl - wc < th - wc)
* * {
* * * return th - wc;
* * }
* if (tl - wc th - wc && th - tl < tl - wc)
* * {
* * * return tl - wc;
* * }
}
main.c
#include <stdio.h>
#include <stdlib.h>
extern double atr ( double th, double tl, double wc );
int
main (int argc, char *argv[])
{
* if (argc != 4)
* * {
* * * fprintf (stderr, "usage error th, tl, wc\n");
* * * exit (EXIT_FAILURE);
* * }
* double th, tl, wc;
* th = strtod (argv[1], NULL);
* tl = strtod (argv[2], NULL);
* wc = strtod (argv[3], NULL);
* printf("%.2f\n", atr(th, tl, wc));
}
You haven''t said what the intent of the atr function is, so how are
we to know whether it is getting the right answer?
Just a bit of math shows that there are cleaner comparisons.
For example,
if ( th - tl th - wc )
is the same as
if ( wc tl )
--
Fred Kleinschmidt
On Jun 11, 11:11*am, "Bill Cunningham" <nos...@nspam.comwrote:* * I have create these 2 files. Called main.c and atr.c. They seem towork
pretty well. I just wanted to submit them to see what if any errors others
that know more might find. Thanks.
atr.c
#include <stdio.h>
double
atr (double th, double tl, double wc)
{
* if (th - tl th - wc && tl - wc < th - tl)
* * {
* * * return th - tl;
* * }
* if (th - wc th - tl && tl - wc < th - wc)
* * {
* * * return th - wc;
* * }
* if (tl - wc th - wc && th - tl < tl - wc)
* * {
* * * return tl - wc;
* * }
}
main.c
#include <stdio.h>
#include <stdlib.h>
extern double atr ( double th, double tl, double wc );
int
main (int argc, char *argv[])
{
* if (argc != 4)
* * {
* * * fprintf (stderr, "usage error th, tl, wc\n");
* * * exit (EXIT_FAILURE);
* * }
* double th, tl, wc;
* th = strtod (argv[1], NULL);
* tl = strtod (argv[2], NULL);
* wc = strtod (argv[3], NULL);
* printf("%.2f\n", atr(th, tl, wc));
}Having fixed some of the more obvious errors, I would try this one:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static double atr(double th, double tl, double wc)
{
if (th - tl th - wc && tl - wc < th - tl) {
return th - tl;
}
if (th - wc th - tl && tl - wc < th - wc) {
return th - wc;
}
if (tl - wc th - wc && th - tl < tl - wc) {
return tl - wc;
}
assert(0);
return sqrt(-1.);
}
int main(int argc, char *argv[])
{
double th,
tl,
wc;
if (argc != 4) {
fprintf(stderr, "usage error th, tl, wc\n");
exit(EXIT_FAILURE);
}
th = strtod(argv[1], NULL);
tl = strtod(argv[2], NULL);
wc = strtod(argv[3], NULL);
printf("%.2f\n", atr(th, tl, wc));
return 0;
}
But then give it inputs of 20 20 20 and see what happens.
这篇关于平均真实范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!