Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator #1116

Open
arunodoy24 opened this issue May 2, 2024 · 0 comments
Open

Calculator #1116

arunodoy24 opened this issue May 2, 2024 · 0 comments

Comments

@arunodoy24
Copy link

#include <stdio.h>

int main() {
char operator;
float num1, num2;

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

printf("Enter two numbers: ");
scanf("%f %f", &num1, &num2);

switch(operator) {
    case '+':
        printf("%.2f + %.2f = %.2f", num1, num2, num1 + num2);
        break;
    case '-':
        printf("%.2f - %.2f = %.2f", num1, num2, num1 - num2);
        break;
    case '*':
        printf("%.2f * %.2f = %.2f", num1, num2, num1 * num2);
        break;
    case '/':
        if(num2 != 0)
            printf("%.2f / %.2f = %.2f", num1, num2, num1 / num2);
        else
            printf("Error! Division by zero.");
        break;
    default:
        printf("Error! Operator is not correct.");
}

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant