Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't do numerical operations with C language. Int variables are not assigned as I specified. randomly determined

    #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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading