We have assignment where we are supposed to code console application, which counts two values, perimeter and volume of triangle and regular hexagon. User should input values accordingly. We should use menu, where user selects which shape he wants to count. As menu i used switch case. I defined functions to count the volume and perimeter outside of main function. Now the problem i have is, that i dont know how to call the functions out of my cases. Hope i described it correctly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Daniel Nosek");
Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
Console.WriteLine("Zvolte si obrazec:");
Console.WriteLine("1 - trojúhelník");
Console.WriteLine("2 - pravidelný šestiúhelník");
int VolbaObrazce = int.Parse(Console.ReadLine());
double obvod = 0;
double obsah = 0;
switch (VolbaObrazce)
{
case 1:
Console.WriteLine("Zadejte délku strany a:");
float a = float.Parse(Console.ReadLine());
Console.WriteLine("Zadejte délku strany b:");
float b = float.Parse(Console.ReadLine());
Console.WriteLine("Zadejte délku strany c:");
float c = float.Parse(Console.ReadLine());
obvod = ObvodTrojuhelniku(a, b, c);
obsah = ObsahTrojuhelniku(a, b, c, s);
break;
case 2:
Console.WriteLine("Zadejte délku strany d:");
float d = float.Parse(Console.ReadLine());
obvod = ObvodSestiuhelniku(d);
obsah = ObsahSestiuhelniku(d);
break;
}
}
static int ObvodTrojuhelniku(int a, int b, int c) // vypocet obvodu pomoci souctu stran
{
return a + b + c;
}
static double ObsahTrojuhelniku(int a, int b, int c, int s) // obsah pomoci heronova vzorce
{
s = (a + b + c) / 2;
return (double)Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
static int ObvodSestiuhelniku(int d) // obvod sestiuhelniku
{
return 6 * d;
}
static double ObsahSestiuhelniku(int d) // obsah sestiuhelniku
{
return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
}
}
}