As an overly broad answer, you need to have an addressable context for the variable you're trying to use. What this really means depends on what you're trying to do and where in the code you're trying to do it. Are the variables global, members of another class, statically accessible. Check out CPlusPlus.com's tutorial on variables as a general reference if you're getting started and Stroustrup's Programming: Principles and Practice Using C++ if you're more of a book person.
In response to your clarification, this is modified from here:
We're within the main() method of the CRectangle class and create a new object of type MyWeirdShape and then call area() to get its size. If this were a static method we could skip the creation of the new object and just call MyWeirdShape::area().
Search about tokenizing and grammar. A very nice example which fits the description of your problem is thoroughly presented in the book : http://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726 among other things.
This will not only allow you to solve this problem but it will also allow you to create a much more powerful calculator, taking into account things such as operator precedence, parentheses, curly brackets etc.
for your reference
https://en.cppreference.com/w/cpp/io/cout
I highly recommend you
https://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726
As an overly broad answer, you need to have an addressable context for the variable you're trying to use. What this really means depends on what you're trying to do and where in the code you're trying to do it. Are the variables global, members of another class, statically accessible. Check out CPlusPlus.com's tutorial on variables as a general reference if you're getting started and Stroustrup's Programming: Principles and Practice Using C++ if you're more of a book person.
In response to your clarification, this is modified from here:
We're within the
main()
method of theCRectangle
class and create a new object of typeMyWeirdShape
and then callarea()
to get its size. If this were a static method we could skip the creation of the new object and just callMyWeirdShape::area()
.Search about tokenizing and grammar. A very nice example which fits the description of your problem is thoroughly presented in the book : http://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726 among other things.
This will not only allow you to solve this problem but it will also allow you to create a much more powerful calculator, taking into account things such as operator precedence, parentheses, curly brackets etc.
There are two ways to do it. I wrote code in VS2017, 1.
2.
for your reference https://en.cppreference.com/w/cpp/io/cout I highly recommend you https://www.amazon.com/Programming-Principles-Practice-Using-C/dp/0321543726