Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
equation calculator
Author Message
nelson

Posted: Thu Dec 04, 2003 9:44 pm   Post subject: equation calculator

ok ,,

azn sensation called me a cheater for asking for codes,

so now i ask nicely if anyone can help me

i need to know how to do this:

user inputs an equation and i need the equation ready for

calculations, so i can get answers by inputing x-values in to the equaition

the program should be able to handle brackets and proper bedmas

example of equation:

y = ((x+3)**2 )**(x+4)+ (x+3x*4x+5x))/3

how would i do this!!?? i'm a newbe.... so plz be detailed ^^

-nel-

Dan

Posted: Thu Dec 04, 2003 10:01 pm   Post subject: (No subject)

well yout going to have to use a loop, substrings and some testing staments to reaed eacech chartier in the input and test to see what it is and what to do.

some things you will have to do:

test, keep track of brackets and the value in them

test for math oprations and what to do for each one (*,+,-,/,**,ect)

use BEDMAS rules you will have to keep track of number befor and after the operation and may be more depending on brackets

chack for x or any other letter and sub in the inputed value.

this will not be that easy to do right, but there are other equatin and math slolving porgames sumited in the turing section witch can help you out.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Andy

Posted: Thu Dec 04, 2003 10:01 pm   Post subject: (No subject)

oo man... i'm not gonna give you the whole code cuz i'm lazy, but i'll give you the basic concept. you get the equation from the user as a string, then get values for x, now using index, replace all the x with the number, and use strint and such to solve
Dan

Posted: Thu Dec 04, 2003 10:06 pm   Post subject: (No subject)

dodge_tomahawk wrote:
...use strint and such to solve

oh you going to do it the cheep way, lol. i like that...
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Andy

Posted: Thu Dec 04, 2003 10:08 pm   Post subject: (No subject)

how else would u do it? if ur not gonna strint the numbers and have if statements for the operators?
Dan

Posted: Thu Dec 04, 2003 10:12 pm   Post subject: (No subject)

oOo, nvm i thougth you ment somting eltes. i forgot turing dose not do that (as in if you have string "1+1" it whould go to 2). i have been doing to many languges lattey all geting mixed together. sory about that mixup. (seems like i am making to many today)
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
nelson

Posted: Thu Dec 04, 2003 10:15 pm   Post subject: hmm

what do you mean by "using index"

and is that a dark templar?
Andy

Posted: Thu Dec 04, 2003 10:20 pm   Post subject: (No subject)

index is a function that returns the first occurence of a substring inside a string. type that on turing and press F9, and yes that is a dark templar as you can see from the cape

nelson

Posted: Thu Dec 04, 2003 10:28 pm   Post subject: d

ok i know how to keep track of things , numbers, +-*/ using strint

and stuff

but i woudn't know how to program where in the equation the calculation

should start

cool
my id is nelsonmuntx in battlenet, if you still play and interested

and HA ! it doesn't say i'm newbe anymore,, TAKE THAT TONY!@!
Tony

Posted: Thu Dec 04, 2003 11:33 pm   Post subject: (No subject)

pff

thats exactly what I told you to do Brian, but NOO...

let me try it again... you start from outside the brackets (if it makes it any easier, put the entire function into another set of brackets to start everything off) and consentrate just on whats inside of those brackets.

if there're another set of brackets inside there, you take just that set and solve that first.

You basically move in, then move out. You'd have to use a self-calling function that accepts a string with part/whole function to break it appart into pieces.

Maybe you'll listen to me now that this is writen down on a forum
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 10 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: