I have created a method that splits a string a^b and converts a and b to doubles. However, if I input the value of either a or b using a fraction (for example 3/5 instead of 0.6) the method doesn't work; it only allows me to input it like 0.6. Why is this, and is it possible to fix it?
The code is shown below:
public static double Coefficient()
{
while (true)
{
string input = Console.ReadLine();
string[] items = input.Split('^');
if (items.Length == 1)
{
if (double.TryParse(items[0], out double A))
return A;
}
else if (items.Length == 2)
{
if (double.TryParse(items[0], out double A) &
double.TryParse(items[1], out double B))
return Math.Pow(A, B);
}
Console.WriteLine("\nPlease follow the specified input form.");
}
}