I made a calculator that works for small numbers but when the results get too large it returns NaN
List<string> memory = new List<string> { };
string display = "";
while (display.Contains("%") == false)
{
string line = ReadLine();
display = line;
memory.Add(line);
}
float result = float.Parse(memory[0]);
for (int i = 1; i < memory.Count; i++)
{
string temp = memory[i];
char[] _temp = temp.ToCharArray();
_temp = _temp.Where(x => x > _temp[0]).ToArray();
float num = float.Parse(string.Join("", _temp));
if (temp.Contains("+") == true) result += num;
else if (temp.Contains("-") == true) result -= num;
else if (temp.Contains("*") == true) result *= num;
else if (temp.Contains("/") == true) result /= num;
else if (temp.Contains("%") == true) result %= num;
}
Take these numbers for example:
797 * 2 + 38 * 212 * 275 * 806 * 67 * 9939 + 7 + 74 + 515 + 610 * 516 * 6921
+ 4 * 2 * 494 * 3153 * 8 + 2501 * 769 + 4 * 2472 + 1 * 21 * 6535 + 30 + 26
+ 44 + 240 + 88 * 1111 * 817 * 1576 + 551 * 535 + 9150 + 36 * 85 * 4598
* 9276 * 766 + 584 + 5 * 1 + 7 + 45 * 8152 % 7984
I enter each number in a new readline with the math symbol infront of it. If you test it with these numbers just be aware.
I've looked everywhere and cant figure out a solution to this problem so that it can return a real number.
Anyone know what I can do to fix this?