Выдает ошибку FormatException при отладке - C#
Формулировка задачи:
Выдает ошибку System.FormatException: "Входная строка имела неверный формат."
И указывает на эту строку
FileStream s = new FileStream("a.txt", FileMode.Open);
в файле ''a'' прописано a=5.0; b=-3.0; c=-14.5; d=9.0; h=0.01;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApp9
{
class Program
{
static double a = 0, b = 0, c = 0, d = 0;
static void Main(string[] args)
{
double h = 0.01, x0 = -100, x1, xn = 100, x;
double[] A = new double[30];
int i = 0;
string st;
FileStream s = new FileStream("a.txt", FileMode.Open);
StreamReader Re = new StreamReader(s);
// Считывание из файла a,b,c,d;
st = Re.ReadLine();
a = Convert.ToDouble(st);
Console.WriteLine("a= {0:f2}", a);
st = Re.ReadLine();
b = Convert.ToDouble(st);
Console.WriteLine("b= {0:f2}", b);
st = Re.ReadLine();
c = Convert.ToDouble(st);
Console.WriteLine("c= {0:f2}", c);
st = Re.ReadLine();
d = Convert.ToDouble(st);
Console.WriteLine("d= {0:f2}", d);
Console.WriteLine("Решение системы неравенств (x+b<0)&&(ax+b>=0)");
Re.Close();
s.Close();
x = x0;
A[0] = x0;
while (x <= xn)
{
x1 = x + h;
if (f(x) ^ f(x1))
{
i++;
A[i] = x + h / 2;
Console.WriteLine("i={0} при x={1:f3} система меняет характер выполнения", i, A[i]);
}
x += h;
}
A[i + 1] = xn;
for (int j = 0; j < i + 1; j++)
{
if (f(A[j] + h / 2))
{
Console.WriteLine("Система неравенств верна на промежутке [{0:f3} ; {1:f3}]", A[j], A[j + 1]);
}
else
{
Console.WriteLine("Система неравенств неверна на промежутке [{0:f3} ; {1:f3}]", A[j], A[j + 1]);
}
}
Console.ReadLine();
}
static bool f(double x)
{
bool z1 = x + b < 0;
bool z2 = a * x + b >= 0;
if (z1 && z2)
return true;
else
return false;
}
}
}Решение задачи: «Выдает ошибку FormatException при отладке»
textual
Листинг программы
a = Convert.ToDouble(st);