FAQ Database Discussion Community

## Java - Always 0?

java,math,coordinates,calculator
i have a normal Java code, that just calculate a x-coordinate, but it is just 0; private static final int startX = (Level.WIDTH / 2) - (Block.LENGTH * (Level.COLUMNS / 2)); At the time of calculating: Level.WIDTH = 1000; Block.LENGTH = 41; Level.COLUMNS = 12; Accord my calculation it must...

## Add a cancel button to input box VB

vb.net,calculator
I have made a simple calculator and I would like to know if you put in a string instead of a double and if you press close or not. The program is a simple calculator where the menu is a box with buttons for addition, subtraction, multiplication, and division. I...

## missing ) after for-loop control - Calculator

javascript,calculator
I try to make a Calculator for Math exercices like : x^2+2(2x+3)+3x But atm I get always missing ) after for-loop control In the code below, I try to find the closest operator (+ or -) to the next (. Maybe I just failed with two for() in one, but...

## Simple Java Calculator to Solve Expressions

java,loops,arraylist,switch-statement,calculator
I'm working on an calculator that solves expressions. I'm trying to figure out how to how make it calculate in PEMDAS order. I have a for loop to traverse the array list and a switch that calls a class that does the math. I've tried if statements, but haven't been...

## Python Restaurant Tip Calculator

python,calculator,python-2.5
So I am a complete newbie to coding and need some help. I am trying to create a code for a tip calculator but am not quite sure where I am going with it. I was never in class to be taught by my teacher so I am going out...

## How to manipulate the result of two parameters with arithmetic operations?

c++,c++11,calculator
Partially Solved Check bellow to see how i solved this silly big problem. I am currently trying to learn how to preform any mathematical operation (in the console) to the result of the previous mathematical operation, for example: user inputs 1 + 2 system("cls"); 3 * 2 system("cls"); 6 /...

## How to store an integer in an activity for calculation

java,android,android-studio,sharedpreferences,calculator
I'm currently creating an application that adds together values to give an overall total, like so. oldValue + newValue = textView1... MainActivity, this is where the overall value is to be stored in textView1 String calorie = getIntent().getStringExtra("calorie"); TextView textView1 = (TextView)findViewById(R.id.textView1); String strOldValue = textView1.getText().toString(); Integer oldValue; try{ oldValue=...

## javascript help using html and calculator

javascript,html,onclick,calculator
Can someone help me to get the total price of the stock given prices below?? Using the onclick, once someone puts in the number of stocks they want to buy, how do I go about getting the total price of all 3 stocks choosen?? <tr> <td><b> SHARE PRICE</b></td> <td>\$43.93</td> <td>\$43.87</td>...

## Error: Can't Assign to Function Call

python,string,variables,integer,calculator
I am trying to make a simple calculator for addition, and am experiencing a problem. print('welcome to calculator') # Print opening message print(' ') #Spacer int(sum1) = input('number') # Get input for first number, this variable later becomes the sum : ERROR: Can't assign to function call int(add1) = input('number')...

## Using keypress to target two different keys within same expression?

javascript,calculator,keypress,keycode
I am building a calculator in vanilla JS and currently have this expression to handle the multiplication: if ((isShift == true && event.keyCode == 56) || event.keyCode == 106){ calc.passMethod('multiply'); } So if someone holds Shift+8 it will multiply. How can I make it so that if someone also hits...

## haskell: binary calculator recursion and return values?

I wanted to change decimal numbers into binary numbers per recursion and if else! binary2 x = if x > 0 then binary x else 999 binary x = if x `mod` 2 > 0 then 1 && binary2 (x/2) else 0 && binary2 (x/2) well returning 0 or 1...

## Need a local storage value to increase on button press

javascript,count,local-storage,calculator
I need to save a value into localstorage thats already in localstorage and only increase that by 1 Save: function checkklaar2() { a = document.getElementById("eindgetal2").value; if (a == "0") { window.location.href = 'winnaar2.html'; var gewonnen2 = localStorage.getItem("setsgewonnen2"); localStorage.setItem("setsgewonnen2.2", gewonnen2.value + "1"); } else {} } View: // Check browser support...

## Eclipse JSwing Calculator

java,eclipse,swing,calculator
I'm trying to make a calculator using the JSwing api. Ive made It about halfway through, got the calculator so that it was mostly functional, but when I was rearranging some code to make it neater as well as add some new options to the calculator, but I ran into...

## Java GPA Calc result Issues [duplicate]

java,eclipse,double,calculator
This question already has an answer here: How do I compare strings in Java? 23 answers GPA Calculator I know there are similar threads out there but none that i have seen have come across the problem I am experiencing. I am receiving no errors yet my final answer...

## Simple calculator in JS

javascript,html,css,web,calculator
I create a simple web app in pure JS and generally I have few issues which I don't know how to solve. First of all, you can see my demo tool here: http://codepen.io/testerius/pen/EaOPEY function calculator() { /* SPEARMAN this code below is for Spearman unit */ // resource requirements var...

## Trouble with basic calculator using switch

java,switch-statement,calculator
I have already researched this question, but could not find an answer that solved my problem. I keep on getting output 0. For this assignment, I'm not allowed to use any methods. In my program, 1+2 equals 0 public static void main(String[] args) { int result = 0; Scanner sc...

## Jquery calculation price of hotel and room with additional price

jquery,html,calculator
DEMO : http://jsfiddle.net/sando779/16wws4w1/ <select name="one" id="one"> <option value="0">Select Hotel</option> <option value="3000">Nirvana</option> <option value="6000">Laguna</option> <option value="9000">Palm beach</option> </select> <br /> <br /> <select name="two" id="two"> <option>Room Type</option> </select> <br/> <br/> <p> <input type="checkbox" name="tri" id="tri" value="50"/> <label...

## Javascript Travel Calculator not working

javascript,calculator
I'm trying to make a JavaScript calculator that will calculate the cost for 4 families to travel by train. The cost for one adult ticket is \$32 and the cost for a child is \$20 with a \$10 commission fee. This is my JavaScript. When i run it in Firefox...

## How do I associate numbers with my array list?

java,android,arraylist,spinner,calculator
I have created two spinners, a meal type spinner (e.g. Breakfast, lunch...) and a food spinner (e.g. porridge). Once the user has selected their meal type the associated foods appear in the second spinner. Now I want to be able to create a food calculator which will multiply a set...

## C# calculator application

c#,calculator
This is the code for the calculator in which i have been attempting to make. I have got it to work except i have one error that i cant seem to figure out how to fix it. whenever the user clicks the wrong operator then clicks the correct one that...

## Mortgage calculator math error

python,math,calculator
This program runs fine, but the monthly payment it returns is totally off. For a principal amount of \$400,000, interest rate of 11%, and a 10-year payment period, it returns the monthly payment of \$44000.16. I googled the equation (algorithm?) for mortgage payments and put it in, not sure where...

## Cannot resolve symbol 'listener'

java,android,button,listener,calculator
I have the following error "Cannot resolve symbol 'listener'" in my following code but can't seem to get rid of this. Any ideas of why this error would appear? public void onClick(View v) { Spinner spr = (Spinner) findViewById(R.id.planspinner); EditText editText6 =(EditText) findViewById(R.id.editText6); TextView textView8 =(TextView) findViewById(R.id.textView8); String selectedItem =(String)...

## Java GUI Calculator

java,swing,user-interface,calculator,jtextarea
My JTextArea does not display and no errors or problems shows up. It's a Java GUI Calculator. Main class code: import javax.swing.JFrame; public class calulator_main{ public static void main(String[] args) { // TODO Auto-generated method stub calulator_ui frame = new calulator_ui(); frame.frame.setVisible(true); } } Calculator code: import java.awt.BorderLayout; import java.awt.FlowLayout;...

## Expanding an arthimetic algorithm for a Weightlifting [closed]

ruby,algorithm,math,calculator
So I am a quite novice programmer, I have been teaching myself Ruby for a couple of weeks now, and I made a program that estimates your 1 repetition max possible weight lifting capabilities. The algorithm I used is: weight = gets.to_i reps = gets.to_i x=Rational(reps,30) x=x.to_f one_RM = weight*(1+x)...

## How can I check that no letters are entered in the array?

java,command-line,calculator
This is a simple calculator program. I just need something to check my array and prevent any letters being in it before my program continues "adding" the two arguments entered. The input is taken from the command line e.g. java adder 1 2 public class Adder { public static void...

## Slider Not Excepting Current Default Value in Swift

Sorry to do this again, but my code has yet ANOTHER problem. When I run the program in the simulator, if I move the slider from its default position and hit the submit button, it will calculate the mpg. However, if I leave the slider at its default position of...

## How to convert a manual sales calculator script into an automatic sales calculator script?

javascript,calculator
I have this manual javascript <head> <script type="text/javascript"> function applyTax(){ var inputAmount = document.getElementById( 'dollars' ).value; var salesTaxGst = (inputAmount / 100) * 5; var salesTaxPst = (inputAmount / 100) * 9.975; var totalAmount = (inputAmount*1) + (salesTaxGst * 1) +(salesTaxPst * 1) ; document.getElementById( 'requestedAmount' ).innerHTML = inputAmount; document.getElementById(...

## Make an dynamically calculator

c#,calculator
i want to make an calculator. my code till now is. string input; input = Console.ReadLine(); List<string> numbers = new List<string>(); string curNumber = ""; foreach (char c in input) { if (c =='+'|| c =='-'||c =='/'||c =='*') { numbers.Add(curNumber); curNumber = ""; } else { curNumber += c.ToString(); }...

## Creating a Profit Calculator

javascript,calculator
I'm trying to create a basic profit calculator but I am struggling with one issue. I've written some basic javascript and the formula almost works. However my issue is that the decimal point doesn't seem to want to work properly. For example: What is the case cost: 2.80 How may...

## Basic Python Calc. - Problems with Bound Methods?

python,python-2.7,calculator
I am trying to make a basic addition class, but I am unable to get python to add the two variables together. When I run the code I get <unbound method Calc.add>. How would I resolve this? num1 = (input("Enter 1st Number: ")) num2 = (input("Enter 2nd Number: ")) class...

## c# Fractional Calculator - Working out Box?

c#,calculator,box
I'm working on a project where I need to develop a fractional calculator. I want to add something extra to it, such as having a working out box that displays how the user got their answer. For example, say I enter 1 1/2 + 1 1/2 into the calculate and...

## Beginner - C# Fractional Calculator simplification of negative fractions

c#,calculator,simplify
I've been having troubles trying to get my fractional calculator to work. I'm trying to get the simplifying to work, it works correctly simplifiyng positive fractions, but if I were to put a negative fraction it won't simplify it, I'm not sure what I'm doing wrong and I've read over...

## String calculator in C with recursion

c,string,recursion,calculator
I am making a string calculator in C, but i have some problems. for example: 2 * (123-321) * (2+(3-4)-(3*2*2)) / ((12-2)/(1+1+1+1+0+ 1)) should print 2178, but instead it prints 3058704. So i tried calculating (2+(3-4)-(3*2*2)) and found it returns 77578153 instead of -11. And also 2*(123-321)*(1-12)/2 returns 1980 instead...

## Why doesn't IF seem to work inside a WHILE loop? (Python 3.4)

python,if-statement,while-loop,calculator,ignore
I am writing the code for a calculator using python. loop = 1 while loop == 1: #loop calculator while loop is TRUE print ("""Options: Addition 1) Subtraction 2) Multiplication 3) Division 4) Quit 5) Reset Sum 6) """) #display calculator's options (' ') #spacer choice = input("option: ") #get...

## Trying to build a calculator in java GUI

java,user-interface,math,calculator
In here im just trying to add first numbers to the second numbers when (=) button is pressed. this code shows only the second number on the screen when (=) button is pressed. once this works i want it to work with different arithmetic operator buttons e.g (+ - *...

## How to do Division in a Fractional Calculator? [closed]

c#,calculator
I'm completely unsure on how to do it. I've searched but can't find a simple answer. I've done the multiplication and I know its similar to it. Need some help. I want to know how to do division for two fractions. My Multiply module: { answerDenominator = num1Denominator * num2Denominator;...

## Netbeans Java GUI calculator - How to perform calculations for more than 2 numbers?

java,parsing,netbeans,calculator
I've made a java calculator in netbeans which performs simple, +-*/ operations to TWO numbers. Code below: @ManagedBean @SessionScoped public class Calculation extends javax.swing.JFrame { double firstNum; double secondNum; double thirdNum; double result; String operation; String operation2; /** * Creates new form Calculation */ public Calculation() { initComponents(); } /**...

## How to express large numbers to the hundredth place in C++ Calculator

c++,decimal,calculator,place
I am trying to write a calculator in c++ that does the basic functions of /, *, -, or + and show the answer to the hundredth decimal place (0.01). For example 100.1 * 100.1 should print the result 10020.01 but instead i get -4e-171. From my understanding this is...

## How to add number below 1 (decimal) onto the end of a number in c#

c#,math,calculator
Hi sorry for the bad title, but this has got me stumped and I need some help. I am making a calculator program in C# that has a GUI. In order to use the GUI I need to make it so that a number is created by clicking numbers one...

## LNK2019 error with simple class [duplicate]

c++,class,calculator,lnk2019
This question already has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 18 answers (Sorry, I know there are many, many posts about this error, but none of them seem to have as simple a program as I'm trying to...

## How do i save next string in scanner? [duplicate]

java,calculator
This question already has an answer here: How do I compare strings in Java? 23 answers Iam making a basic calculator with 3 functions. Iam using a Scanner-utility to help me interact with the calculator. You enter the first number, then it saves it to a variable, You enter...

## How do i display button value in a text field in JavaScript(not JQuery) [closed]

javascript,html5,button,calculator
i have made a simple calculator and i am unable to print the value of my buttons on click onto the text field. How do i do that? I want to use JavaScript only, not JQuery. When i click on my buttons the values are not displaying on the text...

## How do I switch from one method to another with switch statement or loop? [closed]

java,methods,switch-statement,calculator
So far, I've been able to make the methods and allow for the user to exit immediately. What I've been having trouble with is.... Having the user select an operation (add, subtract, multiply, divide) Having a method to choose an operation Then proceeding with the getNumber statement and the different...

## Create a calculator from a spinner

java,android,spinner,calculator
I have created two spinners where the user can select a Meal Type and then select a food, (e.g. 'Breakfast' and 'Porridge'). I then need to times the food calories by the weight the user enters in an Edit Text but I am not sure how I do this. How...

## MYSQL/PHP: Comparing large sets of 2 specific rows in one table (POKER-calculator)

php,mysql,sql,calculator,poker
I am writing an online poker calculator just for fun :) I tried the pure php calculation approach, to compare two hands it calculates the outcome for every possible deck (C(5,48) = 1712304 decks) That takes around 12 seconds on my sucky one.com server :D What is ofcourse far too...

## Linear equation solver Arduino,printing wrong answers

c,matrix,arduino,calculator,linear-algebra
Please help me any help will be appreciated. I wrote a code in C to solve equations, but I don't know why some equations that I input into this calculator, give me wrong values, the algorithm is correct because I execute it in C and give me the correct answers...

## applescript Calculator not working

applescript,calculator
I have made a calculator which should work but doesn't. The only part that works is the addition. this is my code: my Calculator() on Calculator() display dialog "Calculator" buttons {"Add", "Multiply", "Divide"} if button returned of the result is "Add" then display dialog "What plus What?" default answer ""...

## JavaFX begginer's simple calculator event handling

java,javafx,calculator
Hey I'm a begginer at java and i've only been doing this for a short period of time, anyways for my final project in java basics i need to make a simple calculator with a gui, i thought it won't be that hard but i was kinda wrong :P i...

## Remove digits after decimal in Javascript

javascript,decimal,calculator
I am making a converter from GPS Degrees, Decimal Minutes to Degrees, Minutes, Seconds since I have no found one on the internet. Can you please tell me how to get rid of the numbers after a decimal in the calculated total field? <HEAD> <TITLE>Javascript Calculator</TITLE> <SCRIPT language="javascript" type="text/javascript"> function...

## Dividing by half in ruby to create an effective calculator

ruby,calculator
For the past while I've been working on a calculator, but have run into problems when needing to divide by a half. I'll add the offending bit of code along with a loop to keep it open below. on = true while on == true do half = 1.0 /...

## how do you find the square root of a number in applescript

applescript,calculator,square-root
I have a simple calculator code and I want to include square root in it. I am relatively new to applescript and I have no idea how. It might be nooby but thanks anyway!

## Is it bad to use goto in this situation?

c++,calculator
I've been working on a console based calculator app, and I wanted to use 2 functions in order to make it look cleaner (I didn't want main having too many lines), so I decided to use goto to jump from main to my foil function, then another goto to jump...

## (MATLAB) Temporarily storing data in a GUI for plot Arithmetic

matlab,user-interface,math,plot,calculator
Hello I'm having a problem in how to go about making a GUI (using GUIDE) to do some arithmetic on some spectra files (from text files containing x data and y data). I'm trying to make something like a spectrum calculator. So far I have two import file buttons called...

## Looking to add a calculator to calculate today's calories for a food application

java,android,android-studio,calculator
Looking to add a calorie counter, for all food added to a running total. I currently have 2 spinners, 1 food type (breakfast etc), the other is the food itself dependent on the food type selected (breakfast = cereal etc). I've added a weight input so the user can select...

## X and Y Intercepts From Slopes - Python

python,calculator
I have been working on a slope calculator that also finds x and y intercepts... how do I do this in Python? Thanks! Here is my current code: def getSlope(x1, y1, x2, y2): slope = (y2-y1)/(x2-x1) return slope def getYInt(x1, y1, x2, y2): s = getSlope(x1, y1, x2, y2) x...

## Coding a Calculator on Python

python,python-3.x,calculator,intervals
So I'm trying to program a calculator that operates with 5 digits, and then check its interval. Here is the code: def CR5(x): x=float('%s' % float('%.5g' % x)) x="{:.4e}".format(x) return x This seems to be working fine, except that the answer is in string form, but that isn't a problem...

## JavaScript Calculator in my Quiz

javascript,calculator
This is the code I will use for my quiz. What is wrong with the code? On mouse over(button), the html will alert the description of the function, and clicking the button will run the specified function. Then, it alerts the user for the answer of the operation. <script type="text/javascript">...

## Android proration calculator not correct results

android,math,calculator
I am working on a proration calculator app for Android. When I run the code below, I get an incorrect result. public void calc(View v) { double myAmount = Double.parseDouble(amount.getText().toString()); double myDaysLeft = Double.parseDouble(daysLeft.getText().toString()); myAmount = Double.parseDouble(amount.getText().toString()); myDaysLeft = Double.parseDouble(amount.getText().toString()); double calcResult = (myAmount /30) * myDaysLeft; String tot =...

## Calculator in one string with priority

java,regex,string,optimization,calculator
How can I create a better solution without stacks or otherwise optimize this code. import java.util.*; public class Calc { // (15+25)+((15+25)+5) public static String calc(String a, String b, String operator){ switch (operator) { case "+": return Double.valueOf(a) + Double.valueOf(b)+""; case "~": return Double.valueOf(a) - Double.valueOf(b)+""; case "*": return Double.valueOf(a)...