![]() |
|
#1
|
||||
|
||||
char to operatorhello,
Here is my question. Is it possible to go from char to operator. char a='+'; //code to switch from char to operator int b,c=3,d=5; b=c a d; |
|
#2
|
|||
|
|||
|
Not easily with C++. You're best bet is to do a bunch of if statements, so:
CPP / C++ / C Code:
And a switch statement would be neater. GF |
|
#3
|
||||
|
||||
ok thanksI was thinking about implementing a massive switch statement, but I guess the problem goes a little deeper.
I would like to read in equations from a text file and be able to execute them. The equations would be variable and the inputs would be variable. I guess I am looking for a formula builder. |
|
#4
|
|||
|
|||
|
This is exactly my second C++ programming assignment
Which is kinda good & bad news. This is not an easy problem - you'd think it is - but it takes a good bit of work! (I know, I was surprised too). A simple equation "12 / 6" won't be hard to code for, but how about "12 / 3 * 2" And then the dreaded "2 + 12 / 3" What operator first? (They all give you 6, By the way). Take that last equation. Consider a simple parser which will step along the string, chunk (number or operator) by chunk at a time. It'll see 2. Plus sign. 12. Then it'll execute it 2 + 12 =14. Then a division sign. 3. 14/3 = 4.6666... - Not correct! Maybe brackets will help? They will, but it makes the coding tougher. Try some ideas! Have you a lecturer, or are you learning this yourself. This is a tough exercise, but I'll try to help as best I can! GF |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ Irc Bot | Boogy | C++ Forum | 16 | 05-Aug-2006 13:04 |
| help with getting single char | SANman | C++ Forum | 10 | 19-Jul-2006 08:23 |
| convert long to pointer to char | realpopeye | C++ Forum | 2 | 26-Sep-2003 10:22 |
| Operator overloading (not happening) | gmn | C++ Forum | 11 | 30-Aug-2003 08:18 |
| a question about / operator | Charunks | C++ Forum | 2 | 21-Jul-2003 11:38 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The