calculator

Why does pow(5,2) become 24? [closed]

陌路散爱 提交于 2019-12-10 00:35:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm making a simple calculator that you can choose a function, then 2 inputs to get your answer. It's a neat little program and everything is running smoothly except for the powers. Every number works correctly. But according to this: 5^2=24, 5^3=624 . I am using pow(number1,number2) . #include <iostream>

Improve BNF for mathematic expressions

牧云@^-^@ 提交于 2019-12-09 13:48:29
问题 A good exercise while learning programming, is to write a calculator. To do this, I created some kind of DSL in BNF and want to ask for your help to improve it. With this minilanguage you should be able to add , multiply and assign values and expressions to names (a.k.a. create variables and functions). Hava a look at the BNF first: <Program> ::= <Line>(<NewLine><Line>)* <Line> ::= {"("}<Expression>{")"}|<Assignment> <Assignment> ::= <Identifier>"="<Expression> <Identifier> ::= <Name>{"("

Make a calculator's grammar that make a binary tree with javacc

北城余情 提交于 2019-12-09 03:51:04
问题 I need to make a simple calculator (with infix operator) parser that handle the operators +,-,*,/ and float and variable. To make this I used javacc, and I have made this grammar with jjtree. It works but it doesn't ensure that the final tree will be a binary tree, which I need. I want something like 5*3+x-y to generate the following tree : * / \ 5 + / \ 3 - / \ x y What would be a proper grammar to do that, that would not be left-recursive ? 回答1: Something like the following will give you

Only PHP Code Calculator with Clickable Buttons as Input

点点圈 提交于 2019-12-09 03:23:43
问题 I am trying to code a calculator with only PHP and HTML code. The Calculator should look like a real one and the buttons should be clickable. Right now, I am stuck at combining 2 numbers, this means I press one button the number will be shown. But after I press the second button the first value disappears because of the type="submit" . My Question is: How can I save the value and show all pressed buttons together? I know I can do that with a hidden input, but I don't know how to use them

Python creating a calculator

与世无争的帅哥 提交于 2019-12-08 22:36:47
问题 I am fairly new to python. I have been asked to create a calculator using only string commands, conversions between int/string/float etc.(if needed), and using functions is a requirement. while and for loops can also be used. The program needs to take an input of the form x/y or x/y/z, where x y z are any positive or negative number. Where "/" can be replaced by addition multiplication and subtraction as well. And where any number of white spaces can exist between operands and operators. This

Javascript increment a value

こ雲淡風輕ζ 提交于 2019-12-08 13:25:28
问题 I have tried and failed trying to get this to work so time to ask the experts. I've got the following HTML: <input type="button" value="-" class="minus"> <input type="number" value="20" class="input-text"> <input type="button" value="+" class="plus"> <div class="newprice"> 20 </div> Using javascript (jQuery specific is fine) I need to be able to have it so that when someone clicks the plus button, the number inside the .newprice div gets incremented by 20. Likewise when they hit the minus

How to calculate a RPN expression having two different data types in Scala?

老子叫甜甜 提交于 2019-12-08 11:24:34
问题 The following program is suppose to calculate an expression with the possibility of having two different data types , Float and RDD . I already created an RPN from the infix expression and now I am trying to perform calculations on them. Note: I have also overloaded :+,-,/,* for doing calculations on RDD and float . def calcRPN(s: String): RDD[(Int,Array[Float])] = (s.split(' ').toList.foldLeft(Nil: List[Either[Float, RDD[(Int,Array[Float])]]) {foldingFunction}).head def foldingFunction(list:

Android - Help with Calculator Logic

北慕城南 提交于 2019-12-08 11:01:52
问题 I've made a custom dialog that is a simple calculator for addition, subtraction, multiplication and division. I'm having trouble getting the logic of my code correct. Does anyone have any word of wisdom or know of resource I could check out that could help. Below is the code for my custom dialog and the calculator Logic that i'm working on. As it is all the calculations work fine except for when i use the equals button. Calculation I do after that point don't come out right. Thanks!

How to use string tokenizer when reading in from a file?

谁说胖子不能爱 提交于 2019-12-08 08:10:06
问题 I am implementing a RPN calculator in Java and need help creating a class to parse the equations into separate tokens. My input file will have an unknown number of equations similar to the ones shown below: 49+62*61-36 4/64 (53+26) 0*72 21-85+75-85 90*76-50+67 46*89-15 34/83-38 20/76/14+92-15 I have already implemented my own generic stack class to be used in the program, but I am now trying to figure out how to read data from the input file. Any help appreciated. I've posted the source code

How can I accept negative values in Postfix and Infix Notation?

*爱你&永不变心* 提交于 2019-12-08 05:38:41
问题 I've written a few methods for a calculator. One, which evaluates an entered Postfix expression and another, which transfers an entered infix expression into a postfix expression. Both these methods allow multi digit integers aswell as floats for the number input types. Now for my question: I want to include the negative input in both these methods e.g. Infix: "3 * (-1)". However I'm kinda lacking an idea on how to implement this problem. Maybe someone can give me ideas or code examples. I'm