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;
}
}
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 ÷
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
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.
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.