|
-
September 6th, 2009, 01:35 PM
#1
Why getting male sex symbol? char push help
I need to add the operands and then push the result onto the stack, when pushed; it pushes a symbol (add 6 and 5, you get the male symbol). What am I doing wrong, I need the symbol to be 11 (when using 6 and 5)?
Code:
stack myStack;
char arg1; // this will hold the left operand.
char arg2; //this will hold the right operand.
char result; // result of every calculation, to be pushed onto stack.
int main()
{
string s1;
cout << "Input the numbers followed by operator(s): " << endl;
cin >> s1;
for (int i=0;s1[i]!='\0';i++)
{
if (isdigit(s1[i])) //used isdigit to check if number, if true; push.
myStack.push(s1[i]);
else if(s1[i]=='+'){
//int x = int(mystring[i]) - 48;
myStack.pop(arg1); //pops operand off top of stack and into arg1 which is a char data
myStack.pop(arg2); //pops operand off top of stack and into arg2 which is a char data
result = int(arg1)-48 + int(arg2)-48;
//if result is initialized as char, pushes symbol and result is symbol
//if result is initialized as int, pushes symbol but result is correctly outputed below
cout << "arg1 and arg2 and result: " << arg1 << " " << arg2 << " " << int(result) << endl; //The numbers are correct here , 6 5 11. If int() not used, male sex symbol is result.
myStack.push(result); //HOW TO INPUT RESULT????? tried using int(result) and //intresult-48, both do not give the correct 11 when '65+' is unput.
} else
cout << "else called from client" << endl;
}
myStack.displayAll(); //displays contents of stack which should be 11 but comes our as the male sex symbol when inputed '65+' into program. should be 11.
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|