calculator

how to resolve 2+2 and 2++2 conflict

不羁岁月 提交于 2019-12-02 14:51:13
问题 In larger program I have given the following (flex/bison) In flex: pn [\+|\-] dig [0-9]+ exp [e|E]{dig}+ . . . "+" {printf("+ detected\n"); return PLUS_SIGN;} {pn}?{dig}+ { printf("digit detected - %s\n",yytext); sscanf(yytext, "%d", (int*)&yylval); return TYPE_INT;} In Bison: expr: expr PLUS_SIGN expr { $$ = $1 + $3; printf(" $$=%f\n",$$); } | TYPE_INT { $$ = (int)$1; printf(" $$=%f\n",$$); } ; The problem is: When I give 2+2 it recognizes 2 and +2 instead of 2 , + , 2 How can I get it to do

Symfony calculate number of days based on date

[亡魂溺海] 提交于 2019-12-02 14:23:00
问题 I am trying to calculate price for number of days from 1-21 based on date. HomeController $Sql = ' SELECT DISTINCT a.property_id, a.date, a.minimum_stay, a.maximum_stay,a.quantity, a.arrival_allowed,a.departure_allowed, p.duration, p.persons, p.amount, p.extra_person_price, p.minimum_stay AS price_minimum_stay, p.maximum_stay AS price_maximum_stay, p.weekdays, p.period_till, p.period_from, datediff(p.period_till, p.period_from) AS number_of_days FROM availabilities AS a JOIN prices AS p ON a

How to calculate a Mod b in Casio fx-991ES calculator

廉价感情. 提交于 2019-12-02 14:05:55
Does anyone know how to calculate a Mod b in Casio fx-991ES Calculator. Thanks This calculator does not have any modulo function. However there is quite simple way how to compute modulo using display mode ab/c (instead of traditional d/c ). How to switch display mode to ab/c : Go to settings ( Shift + Mode ). Press arrow down (to view more settings). Select ab/c (number 1). Now do your calculation (in comp mode), like 50 / 3 and you will see 16 2/3 , thus, mod is 2 . Or try 54 / 7 which is 7 5/7 (mod is 5 ). If you don't see any fraction then the mod is 0 like 50 / 5 = 10 (mod is 0 ). The

Python Divide by 0 Error

我是研究僧i 提交于 2019-12-02 13:36:04
I am currently using this Python code: valid_chars = "0123456789-+/* \n"; while True: x = "x=" y = input(" >> ") x += y if False in [c in valid_chars for c in y]: print("WARNING: Invalid Equation"); continue; if(y == "end"): break exec(x) print(x) It crashes when the user does something like this: 9/0. Error: ZeroDivisionError: division by zero What are some ways that will prevent the user from dividing something by zero? You can except the ZeroDivisionError like this x = "1/0" try: exec(x) except ZeroDivisionError: print ("WARNING: Invalid Equation") If you are using Python 2.x, the input

my if statement within my switch statement does not work correct within my calculator. need help fixing the divide by 0 error

♀尐吖头ヾ 提交于 2019-12-02 13:14:15
i created a basic calculator, but with division i coded it, that when i divide by zero it will give the error to the user in the 2nd textbox, but now even if i divide by 3 or any other number that is not 0, the error keeps appearing in my second textbox. namespace calc { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page { Double num01 = 0; int Operation = 0; public MainPage() { this.InitializeComponent(); } private void num0_Click(object sender, RoutedEventArgs e) { textbox1.Text = textbox1

How do a simple calculator in Android? How to do it using Buttons and single edit text?

旧城冷巷雨未停 提交于 2019-12-02 10:46:28
I am learning Android so I want to keep things simple. I have to add two numbers and display the result in a single editbox. To add with the second number you have store the first number in a variable. Then later add using this variable with the second number in the edit text. If you look at the xml and Java Code below you will have a better idea. Thanks in advance. <?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout

Symfony calculate number of days based on date

时光毁灭记忆、已成空白 提交于 2019-12-02 10:37:50
I am trying to calculate price for number of days from 1-21 based on date. HomeController $Sql = ' SELECT DISTINCT a.property_id, a.date, a.minimum_stay, a.maximum_stay,a.quantity, a.arrival_allowed,a.departure_allowed, p.duration, p.persons, p.amount, p.extra_person_price, p.minimum_stay AS price_minimum_stay, p.maximum_stay AS price_maximum_stay, p.weekdays, p.period_till, p.period_from, datediff(p.period_till, p.period_from) AS number_of_days FROM availabilities AS a JOIN prices AS p ON a.property_id=p.property_id WHERE a.minimum_stay >0 AND a.maximum_stay < 22 AND a.date >= p.period_from

If using Xcode to make an iOS calculator, how would I add a decimal button?

孤街醉人 提交于 2019-12-02 10:27:13
How to add a decimal button so I don't have to do whole numbers? If i wanted any decimal number like 1.2 or 100.4 or 3.0 or anything like that, how would I add it to the calculator I'm making? You're not giving me much information in your question. How do the other buttons work? If I was making a calculator I would have a label at the top showing the current reading. On press of a number button I would update the label with the number at the end. For a decimal button you just add a . to the end of the label. You might want to have a global variable BOOL hasDecimalPlace and set it to true so

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

半腔热情 提交于 2019-12-02 10:23:05
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 ? Something like the following will give you the tree you asked for. void sum(): {} { term() [ plus() sum() | minus() sum() | times() sum() | divide() sum(

Custom math functions vs. supplied Math functions?

半世苍凉 提交于 2019-12-02 10:15:54
I am basically making a Java program that will have to run a lot of calculations pretty quickly(each frame, aiming for at least 30 f/s). These will mostly be trigonometric and power functions. The question I'm asking is: Which is faster: using the already-supplied-by-Java Math functions? Or writing my own functions to run? The built-in Math functions will be extremely difficult to beat, given that most of them have special JVM magic that makes them use hardware intrinsics. You could conceivably beat some of them by trading away accuracy with a lot of work, but you're very unlikely to beat the