C语言 7-13 日K蜡烛图 (15 分)
输入格式: 输入在一行中给出4个正实数,分别对应Open、High、Low、Close,其间以空格分隔。
输出格式: 在一行中输出日K蜡烛的类型。如果有上、下影线,则在类型后加上with 影线类型。如果两种影线都有,则输出with Lower Shadow and Upper Shadow。
这次的代码是这一题,虽然看上去不难,但是实际写下来费了不少时间~~
int main(){
float Open,High,Low,Close;
int flag1 = 0,flag2 = 0;
scanf("%f%f%f%f",&Open,&High,&Low,&Close);
if(Close<Open)
{
if(Low<Close && Low<Open)
{
flag1 = 1;
}
if(High>Open && High>Close && flag1){
printf("BW-Solid with Lower Shadow and Upper Shadow");
return 0;
}
if(flag1){
printf("BW-Solid with Lower Shadow");
return 0;
}
printf("BW-Solid");
}
if(Close>Open)
{
if(Low<Close && Low <Open)
{
flag2 = 1;
}
if(High>Open && High>Close && flag2){
printf("R-Hollow with Lower Shadow and Upper Shadow");
return 0;
}
if(flag2){
printf("R-Hollow with Lower Shadow");
return 0;
}
printf("R-Hollow");
}
if(Open==Close)
{
if(Low<Open)
{
printf("R-Cross with Lower Shadow");
return 0;
}
if(High>Open){
printf("R-Cross with Upper Shadow");
return 0;
}
printf("R-Cross");
}
}
|