I ma newbie to C# and this piece of code I am trying to use double as data type
using System;
namespace FirstProject
{
class Program
{
static void Main(string[] args)
{
Console.Title = "My First Project";
double num1, num2, div;
Console.WriteLine("Enter The First Number :");
num1 = double.Parse(Console.ReadLine());
Console.WriteLine("Enter The Second Number :");
num2 = double.Parse(Console.ReadLine());
switch (num2)
{
case 0:
Console.WriteLine("Alert Divide By Zero");
break;
default:
div = num1 / num2;
Console.WriteLine("The Result Of Division Is " + div);
break;
}
Console.ReadKey();
}
}
}
The variable num2
has an alert that Error 1 A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type C:\Users\Future\documents\visual studio 2012\Projects\FirstProject\FirstProject\Program.cs 19 21 FirstProject
.. How can I use double in the switch expression?
There is no specific details. The code simply uses two numbers entered by the user then check for the second number. If the second number is zero, alert dislayed else the division result is displayed. (this is for those who asked for more details) When using int instead if double, no errors appeared but when using double to get the result of division as double, I got the error I displayed earlier.