Facebook
From Queen Capybara, 3 Years ago, written in C#.
This paste is a reply to Untitled from Big Pudu - go back
Embed
Viewing differences between Untitled and Re: Untitled
//To wklejasz w funkcji main
Console.WriteLine("Please enter radius: ");
double a = double.Parse(Console.ReadLine());
Console.WriteLine("Please enter generatix: ");
double b = double.Parse(Console.ReadLine());

//zadanie 2
try
{
  Console.WriteLine("Cone field: " + PolePowCalkStozka(a, b));
}
catch (DivideByZeroException e)
{
  Console.WriteLine("Values can't be 0");
}
catch (InvalidOperationException e)
{
  Console.WriteLine("Values must be >0");
}
catch (DataMisalignedException)
{
  Console.WriteLine("You entered incorrect parameters");
}



// a to poza funkcją main 
public static double PolePowCalkStozka(double promien, double tworzaca)
{
  double height = Math.Sqrt(Math.Pow(tworzaca, 2) - Math.Pow(promien, 2));
  double field;
  
  
  if (promien < 0 || tworzaca < 0)
  {
    throw new System.InvalidOperationException();
  }
  else if(promien+height   {
    throw new System.DataMisalignedException();
  }
  else if(promien==0 || tworzaca == 0)
  {
    throw new System.DivideByZeroException();
  }
  else
  {
    field = (Math.PI * promien) * (promien + tworzaca);
    return field;
  }
}