+8

Mathematics - Code Coach Challenge‼️How to consider the fact that an expression can include multiple operations⁉️🤔

My code in C++ & C, fails test 4 & 5 probably because it accepts only one operation in an expression⁉️🤔 I don't want to parse deeper in expression string because of the operators precedence‼️There must be an easier way‼️😃 I don't feel comfortable in C++ & C so help needed⁉️🤔 https://code.sololearn.com/cGy4FlymNnKe/?ref=app

1/22/2020 4:05:35 PM

Janusz Bujak 🇵🇱

10 Answers

New Answer

+7

Actually, yeah, they want you to do longer expressions, handling operators precedence. In Python of course it is trivial, but in C, for me it was quite a fight to get it right. I also think it is one of the few rewarding tasks of Code Coach, so... you sure you don't want to rack your brain about it a while longer? :)

+7

CeePlusPlus Thx, I know ‼️☺️ As HonFu said: In 🐍 this challenge is trivial‼️☺️

+6

Right, Dennis, HonFu Maybe test data are poor (only */+- & never +-*/)⁉️ In other case it would be Anti-Pattern‼️

+3

A trivial answer 😄 https://code.sololearn.com/cZa6PhU2BOQg

+2

You actually don't have to deal with operator precedence in the mathematics challenge, so that's 1 thing less to worry about.

+2

In python, there is a function named eval that actually solves equations, that are in string form. That's how I solved the code coach.

+2

Dennis, you need to do */ first, so isn't that one layer of operator precedence?

+2

HonFu I parsed the expressions in order and did not take operator precedence into account and it passed all tests. I'm guessing there is no */ after a +-.

+1

Ah, okay, so another sloppy set of tests... 🙄 What a pity, otherwise it would be a rather good one, preparing you for more complicated parsing.

+1

David Ashton Thx, this challenge is really trivial in 🐍 but I've been talking about C++ & C‼️ Now it's done ‼️☺️