Help with a little calculator program :/

Here is what I have thus far:

http://www.text-upload.com/read.php?id=314581&c=3847000

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.
Last edited on
Thanks a bunch!!!

I'm not entirely sure what strcmp does, but thanks anyway!
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.
Thanks heaps!!!!!!
Don't worry. What you did was my very first mistake at C++.
Say I wanted to raise a number to the power of another, so I enter
2 4 p

in the parameters box, is there a simple way to do this, or will it require a for loop of some description?
Parameters box? Sorry?
Execute>Parameters
I'm using wxdev
Sorry for my bad c++ lingo

I think the other name for it is the command line,
like if I entered:
2 5 p

How would I make it do:
2^5
1
2
3
// In the includes:
#include <math.h>
// Then use cout << pow(2,5); 
Topic archived. No new replies allowed.