I just wrote my first C# console application, I am still a beginner. Anyway, I tried the code below and it seems to work, its for solving quadratic equations. I'd like to add code for a situation whereby a user inputs a string instead of an integer and give an error message any ideas as to how to implement this?
namespace Quadratic_equation
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("welcome to seyi's quadratic calculator!!!");
Console.Write("a:");
double a = Convert.ToInt32(Console.ReadLine());
Console.Write("b:");
double b = Convert.ToInt32(Console.ReadLine());
Console.Write("c:");
double c = Convert.ToInt32(Console.ReadLine());
if ((b * b - 4 * a * c) < 0) {
Console.WriteLine("There are no real roots!");
}
else {
double x1 = (-b + Math.Sqrt((b*b)-4*a*c)) /2*a;
double x2 = (-b + Math.Sqrt((b*b)-4*a*c)) /2*a;
Console.WriteLine("x:{0}",x1);
Console.WriteLine("y:{0}",x2);
}
Console.ReadKey();
}
}
}