Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 equation calculator
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nelson




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

ok ,,

azn sensation called me a cheater Surprised 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-
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




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

what do you mean by "using index"

and is that a dark templar?
Andy




PostPosted: 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




PostPosted: 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




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

pff Rolling Eyes

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 Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: