Z
Z
zhaneltina2021-03-02 12:52:03
.NET
zhaneltina, 2021-03-02 12:52:03

The input string was not in the correct format. FormatException C# How to fix?

The code seems to be correct, but when I run it, it gives out "The input string had an incorrect format."
The code:

static void Main(string[] args)
{
            string x; // Auxiliary variables
            double t, s = 1;
            Console.WriteLine("Enter the numbers one per line");
            Console.WriteLine(" End – Ctrl + z");
            while ((x = Console.ReadLine()) != null)
            { // End of circle
                t = Convert.ToDouble(x);  //(ругается на эту строку)
                // Repeat steps
                s *= t;
            }
            Console.WriteLine("The product of numbers is {0}", s); // Result
}


How to fix? Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-03-02
@zhaneltina

Deal with the current locale, dot or comma is your decimal separator. Or specify explicitly the desired locale.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question