Skip to content

Instantly share code, notes, and snippets.

@FormerlyZeroCool
Created January 18, 2023 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FormerlyZeroCool/4b4020ec166674c0178f0314816ab8fe to your computer and use it in GitHub Desktop.
Save FormerlyZeroCool/4b4020ec166674c0178f0314816ab8fe to your computer and use it in GitHub Desktop.
#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