Skip to content

Conversation

@muhammadnoorulainroy
Copy link

@muhammadnoorulainroy muhammadnoorulainroy commented Nov 13, 2025

Fix: Calculator Order of Operations (PEMDAS/BODMAS)

Fixes #134

Problem

The calculator was evaluating expressions sequentially from left to right instead of following standard mathematical order of operations, resulting in incorrect calculations.

Examples:

  • 2 + 3 × 4 returned 20 (expected: 14)
  • 10 - 8 / 2 returned 1 (expected: 6)
  • 12 - 3 / 3 returned 3 (expected: 11)

Solution

Implemented a two-pass algorithm to enforce operator precedence:

  1. First pass processes multiplication and division (left to right)
  2. Second pass processes addition and subtraction (left to right)

Test Results

All 14 tests passing:

  • PEMDAS/BODMAS precedence rules are correctly enforced
  • Same-precedence operations are evaluated left-to-right
  • No regressions in existing functionality

Screenshots of Working Functionality

Screenshot 2025-11-13 163757 Screenshot 2025-11-13 163809

@vercel
Copy link

vercel bot commented Nov 13, 2025

@muhammadnoorulainroy is attempting to deploy a commit to the ACM FUN Team on Vercel.

A member of the Team first needs to authorize it.

@muhammadnoorulainroy
Copy link
Author

@Kanavpreet-Singh, please review.

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

Successfully merging this pull request may close these issues.

Calculator Not Following Order of Operations (PEMDAS/BODMAS)

1 participant