Click here to Skip to main content
15,916,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to develop a console application that can calculate the range of a missile. The application asks the user to enter the height of the missile trajectory (suppose H). Once user enters the height, the application then asks the user to enter angle of attack (suppose Theta). The application then calculates the range according to the following formula: using C#

Range= 4*H/tan(theta)
 where      
tan(theta) = sine(theta)/cos(theta)



this is my code:

C#
using System;


namespace Mid2
{
    class Program
    {
        static void Main(string[] args)
        {
            float tan * theta = sin(theta) / Cos(theta);
            Console.WriteLine("Enter the height: ");
            float H = float.Parse(Console.ReadLine());

            Console.WriteLine("Enter the angle: ");
            float theta = float.Parse(Console.ReadLine());

            float Range = 4 * H / Math.tan(theta);
            Console.Write("Result = {0} " +Range);

        }
    }
}
Posted
Updated 24-Oct-15 23:25pm
v2
Comments
Maciej Los 25-Oct-15 5:25am    
And... the issue is...
BillWoodruff 25-Oct-15 13:55pm    
Seems to me you are missing the important "range" factor of the energy/momentum imparted to the missile by its propulsion system.

1 solution

what do you mean with your first line:
float tan * theta = sin(theta) / Cos(theta);

perhaps something like this ?
Func<double, double> tan = x => Math.Sin(x) / Math.Cos(x)


I would change your code snippet to:

C#
void Main()
{
    Func<double, double> tan = x => Math.Sin(x) / Math.Cos(x);
    Console.WriteLine("Enter the height: ");
    double H = double.Parse(Console.ReadLine());
    Console.WriteLine("Enter the angle: ");
    double theta = double.Parse(Console.ReadLine());

    double Range = 4 * H / tan(theta);
    Console.Write("Result = {0} " ,Range);
}



As Math.Sin() returns a double you might want to change your local variables to the same type.
 
Share this answer
 
Comments
Maciej Los 25-Oct-15 10:40am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900