Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I need some help

Name: Anonymous 2009-09-30 1:00

I'm a first time /prog/er here and I know these kinds of threads are looked down upon, but Ive got an assignment due tomorrow and I just started on it a few hours ago. I have to write a Java program that takes in two numbers and a math sign like plus, minus, times and divide and gives the answer. Ive been trying to use parameters but I'm not sure if Im doing it right. Its not compiling yet but this is what I have so far. Any help would be appreciated.


import StringTokenizer
import JOptionPane

public void class calculate
{
    public static void main(string args[])
    {
             int[] para = input;
             if(para[3] = +)
                  para[1+2] = output;
             if(para[3] = -)
                  para[1-2] = output;
             if(para[3] = *)
                  para[1*2] = output;
             if(para[3] = /)
                  para[1/2] = output;
        }
}

Name: >>18 2009-09-30 3:46

Here's a simple arithmethic evaluator I wrote in Common Lisp, just 4 minutes ago:

(defun simple-eval (e)
  (if (atom e) e
      (destructuring-bind (op . args) e
    (assert (member op '(+ - * / sin cos expt)) (op) "Unknown operation ~A" op)
    (apply op (mapcar #'simple-eval args)))))

;;; Examples:
(simple-eval '(+ (* (* 1 2) (/ 1 2)) 0 1 2)) ;=> 4
(simple-eval '(+ (expt (cos 123) 2) (expt (sin 123) 2))) ;=> 0.99999994 in the implementation I'm using, it's not 1 due to floating point errors. Better accuracy can be obtained by tweaking some options, but that's not the point here.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List