# Need to change position of decimal point.

#### jacob_1988

##### Member
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).
```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace rrr
{
class Program
{
static void Main(string[] args)
{

//Prompt user for angle in degrees
Console.Write("Enter initial angle in degrees ");
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 ");
Console.WriteLine();

//Output: distance of the shell
Console.WriteLine("Vertical distance of the shell {0} Meters. \r\n ", h);
}

}
}```

Last edited by a moderator:
The code you have provided is just displaying the data you give it. If it's not displaying what you want then it's because you're giving it the wrong data. That means that the issue is in the code that is calculating 'dx' and 'h', not in the code that displays those values.

So, first of all, provide us with the actual formulae you're trying to implement, then provide us with your implementation and we can probably work out what you're doing wrong.

Updated code as above.

What data are you using?

What data are you using?

Sorry I don't understand the question - what do you mean by which data?

What inputs are you using to get the stated outputs?

Input: 45 (degrees) = 0.10204080?

I've fixed the problem (the alternative code is highlighted in red - as below).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace rrr
{
class Program
{
static void Main(string[] args)
{
//Prompt user for angle in degrees
Console.Write("Enter initial angle in degrees ");

//Prompt user for initial Speed
Console.Write("Enter initial Speed ");
Console.WriteLine();

//Degree * PI / 180
theta = theta * ((float)Math.PI) / 180;

//Calculate vox using the Math.Cos method
float cos = speed * (float)Math.Cos(theta);

//Calculate voy using the Math.Sin method
float sin = speed * (float)Math.Sin(theta);

//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. ", dx);

//Output: distance of the shell
Console.WriteLine("Vertical distance of the shell {0} Meters. \r\n ", h);
}

}
}

Replies
8
Views
3K
Replies
3
Views
3K
Replies
3
Views
2K
Replies
0
Views
3K
Replies
4
Views
7K