In C# its Debugging and I have an error. using System; using static System.Conso
ID: 3719692 • Letter: I
Question
In C#
its Debugging and I have an error.
using System;
using static System.Console;
public class DebugEleven01
{
public static void Main(string[] arr)
{
double salary=0;
string salVal;
bool isValidSalary=false;
while(!isValidSalary)
{try
{Console.Write("Enter an employee's salary ");
salVal = Console.ReadLine();
salary = Convert.ToDouble(salVal);
isValidSalary = true;}
catch(FormatException)
{Console.WriteLine("You must enter a number for the salary");}}
Console.WriteLine("The salary {0} is valid", salary.ToString("C2"));
}
}
Explanation / Answer
using System;
using static System.Console;
public class DebugEleven01
{
public static void Main(string[] arr)
{
double salary=0;
string salVal;
bool isValidSalary=false;
while(!isValidSalary)
{try
{Console.Write("Enter an employee's salary ");
salVal = Console.ReadLine();
salary = Convert.ToDouble(salVal);
isValidSalary = true;}
catch(FormatException)
{Console.WriteLine("You must enter a number for the salary");}}
Console.WriteLine("The salary {0} is valid", salary.ToString("C2"));
}
}
Output: