C++/CLI Operators not working right

Can someone shed a a light on this please
Some operators are not working correctly, is it me that's doing stuff wrong?
I'm working in windows forms c++/cli, visual studio 2013

+ and - does work,
but neither / or * works



private:

void Operand_Vald(Object ^sender, EventArgs ^e)
{
// En operand väljs; utför den senaste operationen och lagra den nya operanden.
Char operation = (dynamic_cast<Button^>(sender))->Text[0];

if (operation == 'C')
{
accumulator = 0;
}
else
{
double aktuelltVarde= double::Parse(textBox2->Text);
switch (lastOperation)
{
case '+':
accumulator += aktuelltVarde;
break;
case '-':
accumulator -= aktuelltVarde;
break;
case '×':
accumulator *= aktuelltVarde;
break;
case '÷':
accumulator /= aktuelltVarde;
break;
default:
accumulator = aktuelltVarde;
break;
}
}

lastOperation = operation;
textBox2->Text = operation == '=' ? accumulator.ToString() : "0";
}
Last edited on
neither / or * works
Sure, because you expect × or ÷.
Yes I know I expect those symbols in my definition, but that only becasue I have assigned them to the windows form with that definition. so buttonDivided is assigned the value of ÷ and buttonMultiply is assigned the value x.

So when I press buttonDivide it makes it ÷, and in the switch the case is for it's value, that is ÷

What is the type of accumulator? What makes you think that it doesn't work?
I still think that it is source and execution charcet difference.

Try to replace them with ASCII characters and try again.
After debugging, it looks like its working, the + and - operations works, but when trying the / or * operations it only redisplays the last number, so if I press 10 * 4, I only get 4, if I press 4*10, I only get 10. Same thing with / operation

But when adding and subtracting it's no issues, then i'ts working correct

accumulator is a double
After debugging
If you did debugging, which lines are executed, step by step. It seems that default branch is executed. I highly suspect that the problem is with different character sets. Do what I suggested in previous post to prove or disprove that.
I tried what you suggested, the / and * works exactly the same for me after changing to / * from ÷ and x
No one else with suggestions? It did no difference in changing the operator symbol, still nothing when dividing or multyplying.

adding and subtracting does work, so the code isn't useless, I know that
Did you change it both at the code and button text?

What is the value of lastOperation when it enters switch as seen in debugger? What is the values of your multipication and division case labels?
Ok i fixed the division and multiplication, it was easy and stupid mistake by me. I copypasted from my .header into my .cpp file of the calculator and it started working right

But I have an issue now, the build breaks everytime I try to use operator on fraction numbers. so I cant do anything like (random number).6345345 and add/subtract divide and multyply without the build breaking.
By any chance do you live in country where decimal separator is comma and not dot? I believe .net number parsing is affected by regional settings by default.
Not sure whats standard here in Sweden, but I think comma might be the standard. Let me try
Thanks, the comma fixed the issue, now the cacluator is working! :D Gonna try to add some more advanced arithemtics later
Topic archived. No new replies allowed.