Home > Blockchain >  Switch/Case exiting the code working when I type in the console C
Switch/Case exiting the code working when I type in the console C

Time:06-19

I am trying to make a basic console script for a calculator as a starter C project. When I type anything after the printf("\nOperator: "); Nothing happens it just exits the program. This shouldn't happen because of the switch statement at line 45

Language: C

Compiler: GCC

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <Windows.h>

int main()
{



    // Variables

    int x;
    int y;
    char op = ' ';
    int sum;
    int difference;
    int product; 
    int quotient;
    int sqrta;
    int logarithm;
    int exponent;

    // Functions

    printf("**FxrMath**\n");
    printf("");
    printf("Options:\n");
    printf("(A)dd\n");
    printf("(S)ubtract\n");
    printf("(M)ultiply\n");
    printf("(D)ivide\n");
    printf("S(q)uare Root\n");
    printf("(L)ogarithm\n");
    printf("(P)ower (x^y)\n");
    printf("(H)ypotoneuse Calculator");
    printf("\n");
    printf("\n**OPERATOR MUST BE LOWERCASE**");
    printf("\n");
    printf("\nOperator: ");
    scanf("%d", &op);

    

    switch (op) // Checking what to do
    {
        case 'a':
            printf("First Number: ");
            scanf("%d", &x);
            printf("\nSecond Number: ");
            scanf("%d", "&d", &y);

            int sum = x   y;

            printf("\n%dSum: ", sum);
            Sleep(2500);
            break;
    

        case 's':
            printf("First Number: ");
            scanf("%d", &x);
            printf("\nSecond Number: ");
            scanf("%d", &y);

            int difference = x - y;

            printf("\n           
  • Related