I am trying to learn more about main() taking arguments. I have tried creating a type of calculator program where you would use this syntax from the command line to calculate.
I am having a problem with the operator part. I know that they will not show up as char type, so would I need to use their ASCII decimal form with my switch statement? Or how can I take different argument types such as, int, char, int?progname 1 + 1
Here is my lame code:
Code:#include <iostream> using namespace std; int main(int *argv) { switch(argv[2]) { case '+': cout << argv[1]+argv[2]; break; case '-': cout << argv[1]-argv[2]; break; case '*': cout << argv[1]*argv[2]; break; case '/': cout << argv[1]/argv[2]; break; default: cout << "\nIncorrect usage.\n"; } return 0; }