calculating user defined formulas (with c++)

前端 未结 8 1623
萌比男神i
萌比男神i 2020-12-29 12:07

We would like to have user defined formulas in our c++ program. e.g. The value v = x + ( y - (z - 2)) / 2. Later in the program the user would define x,y and z -> t

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 12:12

    To make your life easier, I think getting this kind of input is best done through a GUI where users are restricted in what they can type in.

    If you plan on doing it from the command line (that is the impression I get from your post), then you should probably define a strict set of allowable inputs (e.g. only single letter variables, no whitespace, and only certain mathematical symbols: ()+-*/ etc.).

    Then, you will need to:
    Read in the input char array
    Parse it in order to build up a list of variables and actions
    Carry out those actions - in BOMDAS order

提交回复
热议问题