Converting user input, i really need some help here

Ok i need a program (not for school) that can get an equation from a user and solve it

i.e

Enter an equation you ugly HOSEHEAD*. [blue]6(5/(12-5))+2[/blue]

You are a stupid moron if you cant figure this one out:

6(5/(12-7))+2=8, HOSEHEAD!






[red][b][italic][size=3]*real programmers strive to insult the user

Comments

  • : Ok i need a program (not for school) that can get an equation from a user and solve it
    :
    : i.e
    :
    : Enter an equation you ugly HOSEHEAD*. [blue]6(5/(12-5))+2[/blue]
    :
    : You are a stupid moron if you cant figure this one out:
    :
    : 6(5/(12-7))+2=8, HOSEHEAD!
    :
    :
    :
    :
    :
    :
    : [red][b][italic][size=3]*real programmers strive to insult the user
    :

    Yup, it's darn difficult..
    Maybe you should search first for all inner parenthesis and then calculate things inside them and then one level out and so on..
    I've never done this myself (and won't) so I don't know if this is the best (or even working) solution.. :-)

  • Try this (thanks to the Qtopia website):

    http://dmitrybrant.hypermart.net/qb/files/basic/eval.zip

    : Ok i need a program (not for school) that can get an equation from a user and solve it
    :
    : i.e
    :
    : Enter an equation you ugly HOSEHEAD*. [blue]6(5/(12-5))+2[/blue]
    :
    : You are a stupid moron if you cant figure this one out:
    :
    : 6(5/(12-7))+2=8, HOSEHEAD!
    :
    :
    :
    :
    :
    :
    : [red][b][italic][size=3]*real programmers strive to insult the user
    :


  • : Ok i need a program (not for school) that can get an equation from a user and solve it
    :
    : i.e
    :
    : Enter an equation you ugly HOSEHEAD*. [blue]6(5/(12-5))+2[/blue]
    :
    : You are a stupid moron if you cant figure this one out:
    :
    : 6(5/(12-7))+2=8, HOSEHEAD!
    :
    Yo! Monk!

    You can't get to Qbasic's expression evaluator through the input statements so you have to write your own evaluator as Alienripper and Alister have pointed out.

    That is, unless you're sneaky about it. You can write a program that inputs the expression, then this first program writes another second program (in Qbasic) that evaluates the expression and prints the result. Once this second program is written by the first program, it is saved to disk and control is then passed to the second program......

    [code]

    'this program must be saved as EVAL.BAS
    CONST quotes = 34
    INPUT "Enter expression: "; expression$
    CLS
    OPEN "SPAWN.BAS" FOR OUTPUT AS #1
    PRINT #1, "PRINT";
    PRINT #1, CHR$(quotes); "The solution of ";
    PRINT #1, expression$; CHR$(quotes); ";"
    PRINT #1, "LET answer = "; expression$
    PRINT #1, "PRINT";
    PRINT #1, CHR$(quotes); " is "; CHR$(quotes); "answer"
    PRINT #1, "RUN "; CHR$(quotes); "EVAL.BAS"; CHR$(quotes)
    CLOSE #1
    RUN "SPAWN.BAS"

    [/code]

    You will have to add your own input expression validation code.
    For the program to work as-is, the expression 6(5/(12-5))+2
    would have to be input as 6*(5/(12-5))+2.

    Have fun!

    rg

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories