Programming in C# question
After creating this code:
Console.WriteLine("Hello, and Welcome to Shell Bomber!\n");
Console.WriteLine("In this game you will calculate the distance\n");
Console.WriteLine("a shell will rise and travel along the ground ^_^\n");
Console.WriteLine("theta = ?"); // initial angle that you will ask for from the user
double theta = Double.Parse(Console.ReadLine());
Console.WriteLine("v_o = ?"); // initial velocity that you will ask for from the user
double v_o = Double.Parse(Console.ReadLine());
Console.WriteLine("Calculate v_ox"); //Calculate vox = v_ocos(theta
double v_ox = v_o * Math.Cos(theta); //Use the Math.Cos(theta) method
theta = theta * Math.PI / 180.0; // Converts from degrees to radians
Console.ReadLine();
Is the program automatically going to convert the value of double v_ox = v_o * Math.Cos(theta) to a value from the user's input of an angle for theta and an initial value? Because when开发者_Python百科 I run it, the program is not calculating the value? Did I do something wrong or is that just how I made it work?
You need to convert theta
into radians before you calculate v_ox.
Once you've done that, just write the value to the console:
Console.WriteLine("Calculate v_ox"); //Calculate vox = v_ocos(theta
theta = theta * Math.PI / 180.0; // Converts from degrees to radians
double v_ox = v_o * Math.Cos(theta); //Use the Math.Cos(theta) method
Console.WriteLine("v_ox == {0}", v_ox); // Show this, if you want to see the value
Console.ReadLine();
If you mean the program isn't showing you the value, it is because you never WriteLine()
the result.
Are you just missing the line where you output the result to the console? Maybe something like this:
Console.WriteLine("The calculated value is: {0}", theta);
精彩评论