6
Reply

C# Methods

D

D

Nov 9 2011 9:58 PM
3.3k
I'm trying to create a console application that will have 2 input values, one is from 10 to 200 the other an angel between 5 and 85.
I have to convert the angle to radians and then calculate the velocity in meters per second.

I'm having troubles getting the method that I want to convert the angle value input to call that value and convert it to radians.
This is my code so far.
Any help would be appreciated :)


static void Main(string[] args)
        {
           
                Console.Write("\nEnter the velocity: ");
                int iValue1 = GetInt(10, 200);
                Console.Write("\nEnter the muzzle angle in degrees: ");
                int iValue2 = GetInt(5, 85);
        Console.Write("The shot will travel {0} meters.", dTotal);
        }




            private static int GetInt(int small, int large)
            {    
                int iValue1 = 0;
                int iValue2 = 0;


                do
                {
                   
                    try
                    {
                       
                        iValue1 = int.Parse(Console.ReadLine());
                       
                        if ((iValue1 < small) || (iValue1 > large))
                        {
                            Console.WriteLine("The Value entered is out of range.\n");
                            Console.Write("Re-Enter the value: ");
                        }


                    }


                    catch (FormatException)
                    {
                        Console.WriteLine("An invalid number was input.\n");
                        Console.Write("Re-Enter the value: ");
                    }
                    catch (OverflowException)
                    {
                        Console.WriteLine("'An invalid number was input.\n");
                        Console.Write("Re-Enter the value: ");
                    }
                   
                }
                while (!(iValue1 >= small) && (iValue1 <= large));


                return iValue1 + iValue2;


            }


            private static double DegToRad()
            {

                //This will Convert Value2 to Radians (Value 2 * (Math.PI / 180))
            }

           private static double ShotDistance() 
           {
             // Distance = (2 * (Value1)Squared * Cos (Converted Rads) * Sin (Converted Rads) / 9.81
           }

Answers (6)