Home > OS >  I can't do numerical operations with C language. Int variables are not assigned as I specified.
I can't do numerical operations with C language. Int variables are not assigned as I specified.

Time:11-10

    #include<stdio.h>
    
    int main()
    {
        int numberone;
        int numbertwo;
        int process;
        int conclusion;
    
        numberone = 0;
        numbertwo = 0;
    
        printf("Specify First Number");
        scanf("%d",&numberone);
        printf("Your first number is set (%d)\n specify the second number\n",&numberone);
        scanf("%d",&numbertwo);
        printf("your second number is set to (%d)...\n",&numbertwo);
    
        printf("Operations you can do are \n1:addition\n2:subtraction\n3:division\n4:multiplication");
        scanf("%d",&process);
    
        switch(process){
            case 1:
                conclusion=numberone numbertwo;
                printf("The result of the addition operation %d",conclusion);
    
                break;
    
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            default:
            break;
    
        }
    
    
        return 0;
    }


I want to make a simple calculator to learn the logic of switch-case, but as in other programs I make, int variables are very different from the ones I assign from the terminal using scanf. sample output

I defined the Variables in the code to zero

CodePudding user response:

printf("Your first number is set (%d)\n specify the second number\n",&numberone);

it should be

printf("Your first number is set (%d)\n specify the second number\n",numberone);

Otherwise, you print the reference (address) of the variable using a signed integer format which is UB.

  •  Tags:  
  • c
  • Related