449,422 Members | 1,310 Online
Need help? Post your question and get tips & solutions from a community of 449,422 IT Pros & Developers. It's quick & easy.

# algebraic expression 'a*b+c' with CIN .Is it possible?

 P: n/a algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c and expression in a,b,c "<>a; cin>>b; cin>>c; cin>???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!! cout<<"This is a*b+c \n"<< s <
9 Replies

 P: n/a Cristian wrote: algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c and expression in a,b,c "<>a; cin>>b; cin>>c; cin>???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!! cout<<"This is a*b+c \n"<< s <

 P: n/a On Wed, 22 Aug 2007 11:21:39 -0400, "Victor Bazarov" Cristian wrote: >algebraic expression 'a*b+c' with CIN .Is it possible?How to transfer the algebraic expression 'a*b+c' to the variable s(all double) with cout in a "Console Application" ? ]zuip[ >Read a string using 'std::getline'. If you need to calculate theresult of that expression, you'll need to implement an expressionparser. See chapter 6 of TC++PL.V Is there something already prepared ? Chapter 6 is very very crypticccccsss!!!!.....for me.. Heartfelt thankyou Aug 22 '07 #3

 P: n/a On 2007-08-22 17:32, Cristian wrote: On Wed, 22 Aug 2007 11:21:39 -0400, "Victor Bazarov" >Cristian wrote: >>algebraic expression 'a*b+c' with CIN .Is it possible?How to transfer the algebraic expression 'a*b+c' to the variable s(all double) with cout in a "Console Application" ? ]zuip[ >>Read a string using 'std::getline'. If you need to calculate theresult of that expression, you'll need to implement an expressionparser. See chapter 6 of TC++PL.V Is there something already prepared ? Chapter 6 is very very crypticccccsss!!!!.....for me.. Yes, the code is in there, but if you really want to use it you really should take the time to understand it also. -- Erik Wikström Aug 22 '07 #4

 P: n/a > Is there something already prepared ? Chapter 6 is very very crypticccccsss!!!!.....for me.. Maybe you should start learing C++ before you do the hard stuff? Aug 23 '07 #5

 P: n/a Cristian wrote: algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c and expression in a,b,c "<>a; cin>>b; cin>>c; cin>???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!! cout<<"This is a*b+c \n"<< s <

 P: n/a On Thu, 23 Aug 2007 16:42:19 +0300, Juha Nieminen Cristian wrote: >algebraic expression 'a*b+c' with CIN .Is it possible? ]zac..cc[ There's no language feature in C++ itself which would allow this.C++ is a compiled language, it's not an interpreted scripting language.What you want to do is easy to do in scripted languages because thescript interpreter is basically parsing and interpreting the inputsource code all the time. Thus it's trivial to construct an expression(eg. by asking the user for it) and make the interpreter parse andinterpret it. However, C++ is not an interpreted language and thus thiskind of thing is not possible directly. ok but I don't understand why there isn't a library for this (for ex in STD). I intend say: ask for algebraic input( mathematical expressions ex. function) isn't common ? In a scientific program I believe that this ownership is obligatory, if there is not this tool as it can make the consumer to interact with the program and to introduce a mathematical function whose structure cannot be anticipated in phase of compilation? > If you want to be able to parse and interpret mathematical expressionsentered by the user you need a parsing/interpreting library for that.Here's one example of such library: http://iki.fi/warp/FunctionParser/ I have to now develop small forms to personal use but it is probable that in the future can use them for a greater project and therefore before wasting time I would like to know if this your parser is possible to also purchase commercial license and how much coast I apologize you for my bad English Tanks cristian Aug 23 '07 #7