'Where does this value from Stack come from?
public static double izracunaj_skladovni_stroj(Queue<char> postfiksni_izraz)
{
Stack<double> skladovni_stroj = new Stack<double>();
while (postfiksni_izraz.Count > 0)
{
char podatek_ = postfiksni_izraz.Dequeue();
if (jeOperand(podatek_))
{
Console.WriteLine("Podatek trenutni: "+podatek_);
skladovni_stroj.Push(podatek_);
foreach (var item in skladovni_stroj)
{
Console.Write("Skladovni stroj "+item + " ");
}
}
else
{
Console.Write(skladovni_stroj);
double x = skladovni_stroj.Pop();
double y = skladovni_stroj.Pop();
double rezultat = 0;
switch (podatek_)
{
case '^':
rezultat = Math.Pow(y,x);
break;
case '*':
rezultat = y * x;
break;
case '/':
rezultat = y / x;
break;
case '+':
rezultat = y + x;
break;
case '-':
rezultat = y - x;
break;
default:
rezultat = 0;
break;
}
skladovni_stroj.Push(rezultat);
}
}
// na skladu mora ostat samo rezultat
return (skladovni_stroj.Count != 0) ? skladovni_stroj.Pop() : Int32.MinValue;
}
So I am having a problem with wrong value being pushed to "skladovni_stroj", which then leads to wrong result being saved.
For example: Function gets queue named "postfiksni_izraz" which value is: "12+3+"
Then I save the char to new variable named "podatek_".

when I console write the variable "podatek_" it outputs he right value, but when I try to push it in the Stack named "skladovni_stroj", it pushes in the wrong value "49" instead of "1".

... and this is the console output of Stack: "skladovni stroj" and current char : "podatek_":
Solution 1:[1]
So thanks to @HansKesting I got an answer that solved my issue:
skladovni_stroj.Push(Char.GetNumericValue(podatek_));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AquaBalls |

