how come my code is not showing like the one in the picture below.

static void Main(string[] args)
        {
            Console.Title = "ICA18 - Methods";

            Console.WriteLine("{0, 40}", "ICA 18 - Methods");

            double dvelocity = GetDouble("Enter the velocity: ", 10.0, 200.0);
            double dangle = GetDouble("Enter the muzzle angle in degrees: ", 5.0, 85.0);

            double dconvert = Radian(dangle);

            double dResult = ShotDistance(dvelocity, dangle);

            Display(dResult);

            Pause();
        }
        
        static double GetDouble(string sPrompt, double dMin, double dMax)
        {
            double dValue;
            bool bError;

            Console.Write(sPrompt);
            dValue = double.Parse(Console.ReadLine());

            do
            {
                try
                {
                    bError = false;
                    Console.Write(sPrompt);
                    dValue = double.Parse(Console.ReadLine());
                    

                    if ((dValue < dMin) || (dValue > dMax))
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write("\nThe Value entered is out of range");
                        Console.ResetColor();
                        continue;
                    }
                }
                catch (FormatException)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("\nAn invalid number was input.");
                    Console.ResetColor();
                    
                    continue;
                }
                finally
                {
                    Console.Write("\n");
                    bError = false;
                    
                }
                
            }
            
            while (bError);
            return dValue;
        }
        static double Radian(double dAng)
        {
            double dmuzzle = 0.0;
            dmuzzle = dAng * (Math.PI / 180);
            return dmuzzle;
        }
        static double ShotDistance(double dV, double dA)
        {
            double dResult = 0.0;
            dResult = (2 * (dV * dV) * Math.Cos(dA) * Math.Sin(dA)) / 9.81;
            return dResult;
        }

        static void Display(double dR)
        {
            Console.WriteLine("The shot will travel {0} meters.", dR);
        }
        static void Pause()
        {
            string sPlay = "no";
            do
            {
                Console.WriteLine("Run again? \"yes\" to run again: ");
                sPlay = Console.ReadLine();
            }
            while (sPlay.ToLower() == "yes");

        }

the instruction is this:

Main()
The main program will run in a loop allowing it to be repeated. It will call the method GetDouble() twice, to input the firing angle in degrees, the limited range is 5.0 to 85.0 degrees. To input the muzzle velocity in meters/second, the limited range is 10.0 to 200.0 meters per second. The method DegToRad() will be used to convert the angle from degrees to radians. The method ShotDistance() will be used to calculate the distance that the shot will travel. The main program will display the distance the shot will travel as a value expressed in meters, with one decimal place of accuracy. The user will then be asked if they wish to run the program again. If the user responds with "yes" the main program will execute again to perform another calculation.

GetDouble()
Method GetDouble() will have three parameters:
A string to be used to prompt the user for a value to be input.
A double value representing the lowest value that will be accepted by the method.
A double value representing the highest value that will be accepted by the method.
This method will use a loop to force the user to enter a double value that is valid and within the range specified. If the value is out of range display an error message indicating that condition. Use a try/catch block to handle any exceptions that occur with an error message indicating a formatting error. After a valid double has be accepted use the return statement to return that value.

ShotDistance()
Method ShotDistance() will have two parameters:
A double angle expressed in radians.
A double muzzle velocity expressed in meters/second.
This method will calculate the distance the shot will travel as a double value, and return that value. The distance can be calculated by the following equation:
Distance=(2v^2cosφsinφ)/9.81
where: φ is the firing angle in degrees
v is the muzzle velocity in meters per second


Here is an example of the program executing:

Get rid of lines 24 and 25 (and all the extra blank lines). You are doing this in the do/while loop, which is what you need to do.

Replace lines 41 and 50 with bError = true; or you will only ever get one value even if it is wrong.

Get rid of line 55, it makes your loop exit no matter what the user typed in.

Your Pause method should return a boolean letting the Main method know if they user wants to try again. You need to wrap your code in the main method with a do/while so it will do another round if Pause tells it to.

where should i put line 62 (return dValue) after getting rid of line 24,25 and 55.
and i make some change, i got rid of void Pause(), i put the line 83 - 89 to Main Method.

You shouldn't touch line 62.

i did not...it showing an error...

*Use of unassigned local variable 'dValue'*

double dValue = 0.0;

at line 21.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.