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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -