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 #475

Open
Geethesh12 opened this issue Feb 3, 2025 · 0 comments
Open

Calculator #475

Geethesh12 opened this issue Feb 3, 2025 · 0 comments

Comments

@Geethesh12
Copy link

#include <stdio.h>

int main() {
int choice;
float num1, num2;

// Displaying the menu
printf("Simple Calculator\n");
printf("==================\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("Enter your choice (1/2/3/4): ");
scanf("%d", &choice);

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

// Perform the operation based on user's choice
switch(choice) {
    case 1:
        printf("Result: %.2f\n", num1 + num2);
        break;
    case 2:
        printf("Result: %.2f\n", num1 - num2);
        break;
    case 3:
        printf("Result: %.2f\n", num1 * num2);
        break;
    case 4:
        if (num2 != 0) {
            printf("Result: %.2f\n", num1 / num2);
        } else {
            printf("Error! Division by zero.\n");
        }
        break;
    default:
        printf("Invalid choice! Please choose between 1 and 4.\n");
}

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