Basically I want it to add the first two parameters when the third parameter is a.
and I want it to multiply the first two numbers when the third parameter is m.
I plan on adding the other mathematical operations later.
for example, if I enter in:
3 4 a
It should give me 7, but nothing is working D:
Please help!
if(argv[3]="a")
Your mistake?
You are using '=' to check equality.
= assigns "a" to argv[3].
It should be ==.
Same to its else if(...
It so becomes... if(argv[3]=="a")
But then what? It's not a std::string. It will check if their pointers are equal, which is almost always wrong.
So you should use strcmp.
This is the result: if(!strcmp(argv[3],"a"))
Remember: Use that '!' before strcmp. strcmp returns 0 if two strings (char *) are equal.
P.S., don't use system("pause"); , your program will be recognized as a virus. Use getch(); instead.
It means StringCompare. It checks if two strings are equal to another.
But if the strings are equal, it returns 0, and so you need the ! symbol to check if they are equal.