C# ATM Problem [HS08TEST] - Runtime Error(NZEC)

ATM problem on C#

My code is:

using System;  
public class Test  
{  
    public static void Main()  
    {  
        int x = int.Parse(Console.ReadLine());  
        double y = double.Parse(Console.ReadLine());  
        if ((y - x > 0.5) && x % 5 == 0)  
        {  
            Console.WriteLine((y - x - 0.5).ToString("0.00"));  
        }  
        else  
        {  
            Console.WriteLine(y.ToString("0.00"));      
        }  
    }  
}

this is ur corrected code…the 2 inputs are in the same line hence ur console.ReadLine() reads 2 space separated numbers…hence u need to split the string using the Split() function…

using System;
public class Test
{
    public static void Main()
    {
    	string s=Console.ReadLine();
    	string[] s1=s.Split(' ');
        int x = int.Parse(s1[0]);
        double y = double.Parse(s1[1]);
        if ((y - x >= 0.5) && x % 5 == 0)
        {
            Console.WriteLine((y - x - 0.5).ToString("0.00"));
        }
        else
        {
            Console.WriteLine(y.ToString("0.00"));
        }
    }
}
2 Likes

Thanks bro’, that did the trick! Didn’t pay too much attention, it seems :slight_smile:

glad could help…:slight_smile: