繁体   English   中英

我怎样才能缩短我的 if else 代码,其中包含变量的值?

[英]How can i short my if else code which cointais value of variable?

我正在尝试缩短代码,但现在这不起作用。 我需要缩短代码的运行时间。有没有人可以告诉我这段代码的错误和这段代码的解决方案。

# include <stdio.h>
int main( )
{
    int bonus, cy, yoj, yos ;
    printf ( "Enter current year and year of joining " ) ;
    scanf ( "%d %d", &cy, &yoj ) ;
    yos = cy - yoj ;
    ( yos > 3 )? bonus=100:printf ( "Bonus = Rs. %d\n", bonus );
    
    return 0 ;
}

它不是这样工作的。

由于您没有提到如果yos < 3会发生什么,我决定将 bonus 设置为0

printf ( "Bonus = Rs. %d\n", bonus = ( yos > 3 ) ? 2500 : 0 );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM