DarkLightA
11-24-2010, 03:28 PM
I've coded my first program in C#. It's for finding the square root of a number. This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What number?");
string dPre = Console.ReadLine();
decimal dDec = Convert.ToDecimal(dPre);
double d = Convert.ToDouble(dDec);
double sqrtLol = Math.Sqrt(d);
Console.WriteLine(sqrtLol);
Console.ReadLine();
}
static void
}
}
However it seems quite trivial to convert from string to decimal, and decimal to double. Isn't there an easier way?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What number?");
string dPre = Console.ReadLine();
decimal dDec = Convert.ToDecimal(dPre);
double d = Convert.ToDouble(dDec);
double sqrtLol = Math.Sqrt(d);
Console.WriteLine(sqrtLol);
Console.ReadLine();
}
static void
}
}
However it seems quite trivial to convert from string to decimal, and decimal to double. Isn't there an easier way?