#### jacob_1988

##### Member

- Joined
- Mar 3, 2016

- Messages
- 9

- Programming Experience
- Beginner

I have written a small C# program to calculate height and speed (of degrees) but when I output the code - the numbers don't read correctly (or as my course work intended). Example: 45 degrees should read: 1020.408 but the output is: 0.10204080, moreover, the other example (input speed 100) should read: 255.102 but instead outputs: 0.0255102?

I have updated the code (as below).

I have updated the code (as below).

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace rrr { class Program { static void Main(string[] args) { //Prompt user for angle in degrees Console.Write("Enter initial angle in degrees "); float theta = float.Parse(Console.ReadLine()); Console.WriteLine(); //Math.PI / 180 float DtoR = theta * ((float)Math.PI) / 180; //Calculate vox using the Math.Cos method float cos = (float)Math.Cos(DtoR); //Calculate voy using the Math.Sin method float sin = (float)Math.Sin(DtoR); //Time until shell reaches apex float t = sin / (float)9.8; //Height of shell apex float h = sin * sin / (2 * (float)9.8); //Distance shell travels horizontally float dx = cos * 2 * sin / (float)9.8; //Ouput: Distance of the shell Console.WriteLine("Horizontal distance of the shell {0} Meters. \r\n ", dx.ToString("N8")); //Prompt user for initial Speed Console.Write("Enter initial Speed "); float speed = float.Parse(Console.ReadLine()); Console.WriteLine(); //Output: distance of the shell Console.WriteLine("Vertical distance of the shell {0} Meters. \r\n ", h); } } }

Last edited by a moderator: