Created
January 18, 2023 18:28
-
-
Save FormerlyZeroCool/4b4020ec166674c0178f0314816ab8fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
int main() | |
{ | |
//extend this calculator to be able to evaluate eny postfix expression | |
//building a simple calculator | |
std::string input("2 3 -"); | |
std::stringstream tokens(input); | |
int a = 0, b = 0; | |
tokens >> a; | |
tokens >> b; | |
char op = 0; | |
tokens >> op; | |
switch(op) | |
{ | |
case('+'): | |
std::cout<<(a + b)<<"\n"; | |
break; | |
case('-'): | |
std::cout<<(a - b)<<"\n"; | |
break; | |
//add / and * operators | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment