I just started to learn c++ and wrote a simple little calculator program, but i wanted to know what i would need to do to accept command line arguments so that it can work like this:
C:\> calc.exe 5 * 5
5 * 5 = 25
Here is the code that i got so far:
======================calc.cpp===================
==============================================Code:#include <iostream> int main() { int v1, v2, total; char type; std::cin >> v1 >> type >> v2; switch ( type ) { case '+': total = v1 + v2; std::cout << v1 << " + " << v2 << " = " << total << std::endl; break; case '-': total = v1 - v2; std::cout << v1 << " - " << v2 << " = " << total << std::endl; break; case '*': total = v1 * v2; std::cout << v1 << " * " << v2 << " = " << total << std::endl; break; case '/': total = v1 / v2; std::cout << v1 << " / " << v2 << " = " << total << std::endl; break; default: std::cout << "Incorrect format (number * number)" << std::endl; } return 0; }
Any help is appreciated.



LinkBack URL
About LinkBacks


