I don't want the else
statement to return a value, but just run the method again. However, I get compile time error
'Program.Coefficient()': not all code paths return a value.
How do I get rid of this error?
This is the code:
public static double Coefficient()
{
string string1 = Console.ReadLine();
string[] stringArray = string1.Split('^');
double[] doubleArray = new double[stringArray.Length];
for (int i = 0; i < stringArray.Length; i++)
{
doubleArray[i] = Double.Parse(stringArray[i]);
}
if (doubleArray.Length == 2)
{
double coefficient = Math.Pow(doubleArray[0], doubleArray[1]);
return coefficient;
}
else if (doubleArray.Length == 1)
{
double coefficient = doubleArray[0];
return coefficient;
}
else
{
Console.WriteLine("Please follow the specified input form (a^b).");
Console.ReadKey();
Coefficient();
}
}