ManasZore / STM

1 stars 0 forks source link

Calculator #1

Open ManasZore opened 10 months ago

ManasZore commented 10 months ago

include

int main() { char operator; double num1, num2, result;

printf("Enter first numbers: ");
scanf("%lf ", &num1 );

printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);

printf("Enter second numbers: ");
scanf("%lf ", &num2 );

switch (operator) {
    case '+':
        result = num1 + num2;
        break;
    case '-':
        result = num1 - num2;
        break;
    case '*':
        result = num1 * num2;
        break;
    case '/':
        if (num2 != 0) {
            result = num1 / num2;
        } else {
            printf("Error: Division by zero is undefined.\n");
            return 1;
        }
        break;
    default:
        printf("Error: Invalid operator.\n");
        return 1; 
}

printf("Result: %lf\n", result);

return 0; 

}

ManasZore commented 10 months ago

Calculator code

ManasZore commented 9 months ago

include

int main() { char operator; double num1, num2, result;

printf("Enter first numbers: ");
scanf("%lf ", &num1 );

printf("Enter an operator (+, -, *, /): ");
scanf(" %c", &operator);

printf("Enter second numbers: ");
scanf("%lf ", &num2 );

switch (operator) {
    case '+':
        result = num1 + num2;
        break;
    case '-':
        result = num1 - num2;
        break;
    case '*':
        result = num1 * num2;
        break;
    case '/':
        if (num2 != 0) {
            result = num1 / num2;
        } else {
            printf("Error: Division by zero is undefined.\n");
            return 1;
        }
        break;
    default:
        printf("Error: Invalid operator.\n");
        return 1; 
}

printf("Result: %lf\n", result);

return 0; 

}