[C++] calculator using stacks

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

[C++] calculator using stacks

Post by ayu »

A very simple calculator made using stacks, that can perform very simple arithmetic operations.

Source

Code: Select all

http://code.suck-oold.com/133

Example
Type a fully parenthesized arithmetic expression:
(((14*4) + 5) + ((4 * 6) + 10))

That evaluates to 95
Last edited by ayu on 29 Jan 2009, 13:43, edited 2 times in total.
"The best place to hide a tree, is in a forest"

User avatar
computathug
Administrator
Administrator
Posts: 2693
Joined: 29 Mar 2007, 16:00
17
Location: UK
Contact:

Post by computathug »

hmmm sorry to be a knob but something doesn't look right in the equation above. Is it my eyes or is it just random to give a brief explanation?

Probably me smoked too much
:oops:

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

hmm yeah you're right, this would be more accurate.

(((14*4) + 5) + ((4 * 6) + 10))


(((56) + 5) + ((4 * 6) + 10))

(61 + ((4 * 6) + 10))

(61 + (24+ 10))

(61 + 34)

95
"The best place to hide a tree, is in a forest"

ebrizzlez
Kage
Kage
Posts: 732
Joined: 31 Mar 2007, 16:00
17
Location: Hidden in a Buffer Protection.
Contact:

Post by ebrizzlez »

Cats bravo. =D>

By the look of the code you thought this through a little carefully. Most calculators let the cpu just compute the arithmetic value such as:

Code: Select all

int i,i2;
cin>>i; //Input first int.
cin>>i2; // Input Second Int.
int add = i+i2; //Results.
Which the code above is only limited to two integers or how many integers the programmer supplied, but your code goes beyond that level. And plus extra karma for using different libraries rather than just cheating and using the <math> library. :wink:

Is this one of your Uni assignments btw?
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Jupp it's an assignment for tomorrow =)
"The best place to hide a tree, is in a forest"

ebrizzlez
Kage
Kage
Posts: 732
Joined: 31 Mar 2007, 16:00
17
Location: Hidden in a Buffer Protection.
Contact:

Post by ebrizzlez »

Nice. :lol:

I've seen Uni has greatly improved your programming skills. Which is awesome man.

Good luck. :wink:
[img]http://i81.photobucket.com/albums/j205/ebrizzlez/4lsint1.jpg[/img]

Post Reply