Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

i am trying to short the code but now this is not working. i need to short the code for it’s run time.Is there nayone who can told me the error of this code and solution of this code.

# 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 ;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It does not work like this.

As you do not mention what should happen if yos < 3 I decided to set bonus to 0.

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading