Hi buddys
at school we are now working with functions and derivates (or how you spell it) and im getting kind of tired to write the same thing the hole time in the calculator and on the paper plus the fact that i need something to program. So i was now trying to do the simple program first to use in the terminal(but then im going to develop it maybe into an applet), but the thing is that i cant find the way to make the user to input the functions both letters and numbers in an easy way to let me then work with them. so my question is...
how can i make it possible to like write 2x^2+3x-1 and then make it possible for me(through the program) to separate all the parts.. and the rest i can figure out. but just how you would have solve the problem of input.

Thanks

P.S.
sorry didnt write that the language im using is JAVA...thats kind of vital to know ;)

P.P.S.
dont want the code just how you would solve the problem of inputing

Recommended Answers

All 3 Replies

so my question is...
how can i make it possible to like write 2x^2+3x-1 and then make it possible for me(through the program) to separate all the parts..

sorry didnt write that the language im using is JAVA...thats kind of vital to know ;)

You're posting in the Java forum so we assume you want to use Java. As for the input - is your question how can you let the user input the items, or is it how can you parse the input? Parsing in this case means taking something like 2x^2 + 3x + 1 and programmatically separating it into logical parts (so that your program knows to treat it as 2x squared, plus 3x, plus 1).

Anyway, you have a variety of ways that you can have the user enter the input. Like you just showed, you could just let them type in something like 2x^2. Or you could design a GUI that had appropriate buttons on it where the user could enter their expressions. From the standpoint of parsing and error control, having a GUI where the user can enter their expressions would make your job much easier. If you let the user type anything they want, you have a high risk that they will enter something you don't know how to deal with.

You'll need to write an expression parser.
Not a beginner's job, though not all that tricky.
There are several books (and no doubt websites) that contain sample code for simple parsers that you can use for inspiration.

ok so parse is the thing i was looking for, kind of difficult to search the web for something i dont know how its called ;)
thanks so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.