14 votes
Accepted

Equation Evaluator

In real life, I would use knowledge of existing libraries to pull out an almost-finished solution. In particular, I think it is an example for Boost.Spirit, which is what I would use for a real ...
JDługosz's user avatar
  • 11.3k
11 votes
Accepted

A queue based calculator for basic math operations

I see a number of things that may help you improve your code. Add error checking Data input usually requires a lot of careful consideration for most software. Checking for malformed input and ...
Edward's user avatar
  • 66.4k
10 votes

Validator for mathematical expression in infix form

Don’t write using namespace std;. You can, however, in a CPP file (not H file), or inside a function, put individual ...
JDługosz's user avatar
  • 11.3k
9 votes

Primitive console string calculator in C

Design #define VAL 1 #define SUB '-' #define ADD '+' etc. are too generically named. Suggest a naming convention that does not so readily conflict with other code....
chux - Reinstate Monica's user avatar
9 votes
Accepted

Shunting-yard algorithm for expression parser

isInteger is not needed. Use std::isdigit. Trust the logic. An else if condition is mutually ...
vnp's user avatar
  • 56.3k
9 votes

Console calculator, takes a string as input (like: 2+3*4-1+3) and outputs the result

Some quick observations: Don't use using namespace std Prefer using \n over std::endl ...
yuri's user avatar
  • 4,448
8 votes
Accepted

Primitive console string calculator in C

Generalities and trivialities: I recommend #includeing all wanted system headers before any private headers. This avoids any possibility of changing the meaning of ...
PellMel's user avatar
  • 911
8 votes
Accepted

Evaluating arithmetic expressions

Spacing I'd like to see some more blank lines. They help separate code into blocks. Without a blank line here and there, the code looks like a wall of text. As someone who answers questions on Stack ...
zondo's user avatar
  • 3,787
8 votes

Python calculator taking string input

On top of the other very good answers: Code organisation and tests It is a good idea to separate the logic about input/output from the logic computing results. In your case, you could have a ...
SylvainD's user avatar
  • 29.2k
8 votes

Calculator using variable names

I think your solution does work, but it's very long-winded. Your IN: and OUT: comments should be moved to docstrings ...
Reinderien's user avatar
  • 60.5k
7 votes

Primitive console string calculator in C

First, things my compiler complains about with warnings turned on: As PellMel has already said, you haven't declared the return type of main. It's good practice to ...
jacwah's user avatar
  • 2,661
7 votes

If ComparisonIsTrue(thisPost, ComparisonOperator.NotEqualTo, goodCode) Then Me.Answer

I really don't like your GoTos... ...
Pimgd's user avatar
  • 22.3k
7 votes
Accepted

Creating truth table from a logical statement

1. Bugs There's an infinite loop in solve: ...
Gareth Rees's user avatar
  • 49.6k
7 votes

Evaluating arithmetic expressions

1. Review The error messages are not very helpful: ...
Gareth Rees's user avatar
  • 49.6k
7 votes
Accepted

Interpret English as Math and Perform Operations

How should I be naming variables? Operation and numInString good names? Great question, Python has an extensive but approachable style guide call PEP8. Specifically local variables should be ...
Zak's user avatar
  • 211
7 votes

Command line calculator in C

General Observations I'm going to address coding style here, since the code is almost unreadable. If you are interested in getting your code reviewed you may want to pay attention to what the ...
pacmaninbw's user avatar
  • 23.8k
7 votes

Command line calculator in C

Don't write clever code: if (printf("%g\n", b(&(const char *){*argv}, 0)) < 0) You know you’re brilliant, but maybe you’d like to understand what ...
Harith's user avatar
  • 4,021
6 votes

Python calculator taking string input

your english is more than good ;) Very small comments to give some advice at this level: Try a bit better naming for functions, is vital for anyone that will read your code to help understand them. ...
A. Romeu's user avatar
  • 1,065
6 votes

Python calculator taking string input

When you're writing a computer program in any language, one of your goals should be to eliminate duplicated code. Computers are good at doing the same task over and over again, even with slightly ...
Snowbody's user avatar
  • 8,442
6 votes

Expression calculator in Python

Nice job with your calculator. Overall it's pretty clean, and you have decent use of functions to break behaviors up. But, I'm very nit picky and am going to recommend some really aggressive ...
Bailey Parker's user avatar
6 votes

Validator for mathematical expression in infix form

I’ll go over check_expression itself, the meat of your logic, in a separate message. Your other functions are just incidental and you just need to learn what’s ...
JDługosz's user avatar
  • 11.3k
6 votes
Accepted

Console calculator, takes a string as input (like: 2+3*4-1+3) and outputs the result

Don’t write using namespace std;. You can, however, in a CPP file (not H file) or inside a function put individual ...
JDługosz's user avatar
  • 11.3k
6 votes
Accepted

Shunting-yard algorithm

Interface design Note that you only support nonnegative integers as operands. Your algorithm correctly rearranges the input tokens in postfix order, but it would be more useful if it preserved the ...
200_success's user avatar
6 votes
Accepted

Synthetic division calculator

Currently some of your code is very specialized to the exact use case you have. For example, the get_factors function takes the unparsed equation and needs to ...
Graipher's user avatar
  • 40.9k
6 votes
Accepted

Evaluating arithmetic expressions and plotting graphs

Since you mention that this was originally C++ code, well it shows. First, style. Python has an official style-guide, PEP8. It recommends writing if condition ...
Graipher's user avatar
  • 40.9k
6 votes
Accepted

Infix to Postfix Converter in C++

std::getline is defined in the include <string>, which you do not have, so the code doesn't compile for me. Don't do ...
pm100's user avatar
  • 781
6 votes

Mathematical expression evaluator (C++)

For a beginner this already quite advanced and well-written code. Improving custom exceptions It's great that you have custom exceptions that derive from ...
G. Sliepen's user avatar
  • 54.1k
5 votes
Accepted

Parsing/RPN calculator algorithm

Overall, your code is pretty readable and understandable. There is an unneeded type on tokens; it can just be Vec<_>. ...
Shepmaster's user avatar
  • 8,628
5 votes
Accepted

If ComparisonIsTrue(thisPost, ComparisonOperator.NotEqualTo, goodCode) Then Me.Answer

Invalid input Consider the following example (Example 1): You have a cell A1 containing the value 3. Now assume the following call: ...
Heinzi's user avatar
  • 566
5 votes
Accepted

CodeWars mathematical expresion evaluator

Single responsibility principle ...
Caridorc's user avatar
  • 27.5k

Only top scored, non community-wiki answers of a minimum length are eligible