DCP-35: Square Number. Parsing Error

Dev Skill archived problems can be discussed here.

DCP-35: Square Number. Parsing Error

by tanmoycsit » Tue Jan 03, 2017 6:04 pm

Hi everyone.

I am using c# and below code is running fine in my Visual Studio 2010. But when i submitted this code it shows an error for parse double. Can anyone please tell me what is the problem of my code?

MY code:

using System;

Code: Select all
public class Test
{
   public static void Main()
   {
      string TestCases = "";
            TestCases = Console.ReadLine();
            int tCases = int.Parse(TestCases);
            for (int i = 0; i < tCases; i++)
            {
                double val = double.Parse(Console.ReadLine());
                double reminder = Math.Sqrt(val) % 1;
                if (reminder.Equals(0))
                {
                    Console.WriteLine("Case " + (i + 1) + ": YES");
                }
                else
                {
                    Console.WriteLine("Case " + (i + 1) + ": NO");
                }
            }
   }
}


Error is :

Code: Select all
Unhandled Exception:
System.FormatException: Invalid format.
  at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in
 
Posts: 2
Joined: Tue Jan 03, 2017 5:54 pm

Re: DCP-35: Square Number. Parsing Error

by devskill » Fri Jan 06, 2017 8:24 pm

Seems like you expected something but the token is something else.

That is why the parse failed. You can try more input / output to find out the bug.
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron