calculator

Calculator in java [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 09:44:19
Lately I've worked on simple calculator that can add, substract, multiply and divide. public static void main(String arr[]){ double num1, num2; String ans = null; System.out.println("Calculator manu:"); System.out.println("\n"+"a for adding"); System.out.println("b for substracting"); System.out.println("c for multiplying"); System.out.println("d for dividing"); Scanner NumInput = new Scanner(System.in); System.out.println("\n"+"Enter number one: "); num1 = NumInput.nextDouble(); System.out.println("\n"+"Enter number two: "); num2 = NumInput.nextDouble(); while(true) { Scanner AnsInput = new

How do I sum numbers using a prompt, like a simple calculator? [duplicate]

雨燕双飞 提交于 2019-12-02 09:40:28
This question already has an answer here: Sum of two numbers with prompt 8 answers I tried to do a REALLY simple thing using JavaScript, a percentage calculator. This is the code: var num = prompt("What is the number?") var perc = prompt("What is the percentage of change?") var math = num / (perc + 100) * 100 var result = alert(eval(math)) But, for some reason, I can sum, for example: var num1 = 15 var num2 = 100 alert(num1 + num2) It will display 115, but I can't sum using something like this: var num1 = prompt("Input a number.") var num2 = 100 alert(num1 + num2) If I write 15 in num1, the

How to let the user reuse a result from the previous computation in a python calculator

感情迁移 提交于 2019-12-02 09:06:32
I am fairly new at python so I don't know much about it. I made a calculator and I want it to accept a: ans() input. Currently, there is a part that stops the program from executing an input if there is something other than [0-9 */-+] so it does not crash. How can I make ans() represent the output of the equation last entered so I can enter something like this: >> 8*8 #last input 64 #last output >> ans()*2 #current input 128 # current output Hopefully I explained everything correctly and here is my code: valid_chars = "0123456789-+/* \n"; while True: x = "x=" y = input(" >> ") x += y if any(c

Simple calculator using command line with C++

☆樱花仙子☆ 提交于 2019-12-02 08:16:59
I'm writing a project that we do simple calculator from command line. The users input in this format programname firstNumber operator secondNumber . Here what I got so far: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main(int argc, char* argv[]) { cout << fixed << setprecision(2); if (argc != 4) { cerr << "Usage: " << argv[0] << " <number> <operator> <number>" << endl; exit(0); } else { double firstNumber = atoi(argv[1]); char theOperator = argv[2][0]; double secondNumber = atoi(argv[3]); switch (theOperator) { case'+': { cout << "The answer is " <<

send javascript variable to classic asp

半城伤御伤魂 提交于 2019-12-02 06:23:23
I have a jQuery-powered cost calculator, and I want to allow the webpage to send a summary of the calculator's values in an email. The server runs on classic ASP. How do I retrieve javascript variables with ASP? I understand that the ASP code runs before the page loads, and the javascript code runs only after the page is loaded, since the javascript is not runat="server". How can I store javascript variables so that I can retrieve them with ASP code on a processing page? calculator with Javascript --> form action = "process.asp" --> ASP to pick up javascript values College Cost Calculator

How to properly parse numbers in an arithmetic expression, differentiating positive and negative ones?

筅森魡賤 提交于 2019-12-02 06:12:44
问题 I have an assignment in my Data Structures class in which I have to program a calculator that solves arithmetic expressions with the 4 basic operations and parenthesis, the input is done via the stdin buffer and the same with the output. It was easy at the beginning, the teacher provided us the algorithms (how to transform the expression from the infix to the postfix and how to evaluate it) and the only goal was for us to implement our own stack and use it, but the calculator itself does not

Scientific notation android java

烈酒焚心 提交于 2019-12-02 06:07:39
问题 I've coded a simple calculator with java for android. I use double as my variables. The results it gives me are in scientific notation after it reaches a certain number of decimals although there is still is plenty of room for decimals. Is there any easy way I can convert scientific to "normal" notation? I can now perform +,-,* and / with a button each. Input the two numbers to calculate in a edittext each. I output my result into another textfield. For example: If I multiply 25 by 1'000'000

Javascript calculator result flashes

让人想犯罪 __ 提交于 2019-12-02 04:21:16
My Code: "edited, added "var" in front of all variable, thanks. I tried removing the <form> but it wouldn't function when I did. <head> <title>Calculator</title> <script language="javascript"> function calculate() { var v=parseInt(document.forms[0].txt1st.value); var w=parseInt(document.forms[0].txt2nd.value); var x=parseInt(document.forms[0].txt3rd.value); var y=703; var z = (v/w/x*y).toFixed(3); document.getElementById("display").innerHTML=z; } </script> </head> <body> <form name="cal" method="post" action=""> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input

Add text to two textfields with JButtons

匆匆过客 提交于 2019-12-02 01:03:21
问题 If my question wasn't very specific, here is what I am trying to do. I have a calculator that has two JTextFields, a JLabel ("Answer = "), and a JTextField for the answer. I have an array of JButtons (0 through 9) that allow the user to click on them to add the number to the JTextField with the cursor active in it... which is the problem here. I can only have one of the two textfields add numbers to them or both add the same numbers to each other. For example, if I click on a button and the

How to properly parse numbers in an arithmetic expression, differentiating positive and negative ones?

断了今生、忘了曾经 提交于 2019-12-02 00:13:21
I have an assignment in my Data Structures class in which I have to program a calculator that solves arithmetic expressions with the 4 basic operations and parenthesis, the input is done via the stdin buffer and the same with the output. It was easy at the beginning, the teacher provided us the algorithms (how to transform the expression from the infix to the postfix and how to evaluate it) and the only goal was for us to implement our own stack and use it, but the calculator itself does not work quite well, and I think it is because of my parser. This is the algorithm , and my code, used to