if statement - (c) expression must be a modifiable lvalue -
if (operation = '+' || operation = '-' || operation = '*' || operation = '/' || operation = '%')//error line { printf("enter first operand:\t\t"); getchar(); scanf("%d", &num1); printf("enter second operand:\t\t"); getchar(); scanf("%d", &num2); } it gives out error saying :
error: expresion must modifiable value it gives me error on if line , on of arguments 1 says
operation = '%' what problem ?? thank guys :)
you made typo , instead of comparison operator == wrote assignment operator =
instead of
if (operation = '+' || operation = '-' || operation = '*' || operation = '/' || operation = '%') there must be
if (operation == '+' || operation == '-' || operation == '*' || operation == '/' || operation == '%') you write if statement simpler. example
const char *operations = "+-*/%"; char *p = strchr( operations, operation ); if ( p != null ) { printf("enter first operand:\t\t"); getchar(); scanf("%d", &num1); printf("enter second operand:\t\t"); getchar(); scanf("%d", &num2); } or without declaring pointer p
const char *operations = "+-*/%"; if ( strchr( operations, operation ) != null ) { printf("enter first operand:\t\t"); getchar(); scanf("%d", &num1); printf("enter second operand:\t\t"); getchar(); scanf("%d", &num2); }
Comments
Post a Comment