自己做的,利用了if循环,但是是错的
#include<stdio.h>
int main(){
double open,high,low,close;
scanf("%lf %lf %lf %lf",&open,&high,&low,&high);
if(open>close){
if(low<close){
if(high>open){
printf("BW-Solid with lower shadow and upper shadow\n");
}
else printf("BW-Solid with lower shadow\n");
}
else if(low>close){
if(high>open)printf("BW-Solid with upper shadow\n");
else printf("BW-Solid\n");
}
}
else if(open==close){
if(low<close){
if(high>open){
printf("R-Cross with lower shadow and upper shadow\n");
}
else printf("R-Cross with lower shadow\n");
}
else if(low>close){
if(high>open)printf("R-Cross with upper shadow\n");
else printf("R-Cross\n");
}
}
else{
if(low<open){
if(high>close){
printf("R-Hollow with lower shadow and upper shadow\n");
}
else printf("R-Hollow with lower shadow\n");
}
else if(low>open){
if(high>close)printf("R-Hollow with upper shadow\n");
else printf("R-Hollow\n");
}
}
return 0;
}
转别人的
#include<stdio.h>
int main()
{
double open,close,high,low;
scanf("%lf %lf %lf %lf",&open,&high,&low,&close);
{
if(close<open)
printf("BW-Solid");
else if(close>open)
printf("R-Hollow");
else
printf("R-Cross");
}
{//上下影线都存在的情况,记得加上前面的空格
if((low<open&&low<close)&&(high>open&&high>close))
printf(" with Lower Shadow and Upper Shadow");
//下影线
else if(low<open&&low<close)
printf(" with Lower Shadow");
//上影线
else if(high>open&&high>close)
printf(" with Upper Shadow");
}
return 0;
}
首先,printf可以分开来(原来!),其次,当说high的时候就是比close和open都大。