c - My IF program is incorrect -


the problem having output '-1' regardless of enter.

the rules must follow are: outputs -1 if input number less zero; outputs 0 if input number zero; outputs 1 if input number greater zero.

code below:

#include <stdio.h> int main () {    int number;  printf("please enter number: "); scanf("%i", &number);  if("number > 0") { printf ("-1"); } else if ("number == 0") { printf("0"); } else if ("number < 0") { printf("1"); } } 

in these if-else statements

if("number > 0") { printf ("-1"); } else if ("number == 0") { printf("0"); } else if ("number < 0") { printf("1"); } 

there used string literals example "number > 0" condition expressions. string literals used in expressions converted pointers first character , unequal 0. tthus first condition in if-else statements yields true.

i think mean following

if( number > 0 ) { printf ( "1");          ^^^^^  } else if (number == 0) { printf("0"); } else  { printf("-1");        ^^^^^ } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -