1

According to the operation entered from the keyboard, I want to do 5 operations with the switch structure, but gives an error. I tried also getchar & putchar functions...

    int main()
    {
        char proc;
        int firstNum,secondNum,result;
        printf("* Multiplication\n/ Division\n+ Add \n- Minus\n%c Mode", '%');
        printf("\nEnter the first number: ");
        scanf("%d",&firstNum);
        printf("\nEnter the second number: ");
        scanf("%d",&secondNum);
        printf("\nEnter the process: ");
        scanf("%c",&proc);

        switch(proc) {
        case '*':
            result=firstNum*secondNum;
            printf ('%d',result);
            break;
        case '/':
            result=firstNum/secondNum;
            printf ('%d',result);
            break;
        case '+':
            result=firstNum+secondNum;
            printf ('%d',result);
            break;
        case '-':
            result=firstNum-secondNum;
            printf ('%d',result);
            break;
        case '%':
            result=firstNum%secondNum;
            printf ('%d',result);


    break;
    default:
        printf('Warning!');
        break;
}

warning: multi-character character constant [-Wmultichar]

warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Emre
  • 35
  • 5
  • 3
    `'%d'` should be `"%d"`. `'Warning!'` should be `"Warning!"`. `'` and `"` aren't interchangeable. – Blaze Oct 21 '19 at 13:22
  • 1
    In some computer languages they are interchangeable (so long as they are paired correctly), but not in C. – Weather Vane Oct 21 '19 at 13:23

1 Answers1

2

For starters use

scanf(" %c",&proc);
       ^^^

(see the blank before the character &) instead of

scanf("%c",&proc);

And use double quotes to specify string literals in statements like this

printf ( "%d",result);
         ^^^^

or this

 printf("Warning!");
       ^^^      ^^^ 

And you forgot one closing brace in the end of the program.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335