I am confused about a few things regarding exercise 3 of chapter 5.
The code from the book of application is here:
Code:
namespace ConsoleApplication1
{
enum orientation : byte
{
north = 1,
east = 2,
south = 3,
west = 4,
}
struct route
{
public orientation direction;
public double distance;
}
class Program
{
static void Main(string[] args)
{
route myRoute;
int myDirection = -1;
double myDistance;
Console.WriteLine("1) North\n2)East\n3)South\n4) West");
do
{
Console.WriteLine("Select a direction:");
myDirection = Convert.ToInt32(Console.ReadLine());
}
while ((myDirection < 1) || (myDirection > 4));
Console.WriteLine("Input a distance:");
myDistance = Convert.ToDouble(Console.ReadLine());
myRoute.direction = (orientation)myDirection;
myRoute.distance = myDistance;
Console.WriteLine("myRoute specifies a direction of {0} and a " +
"distance of {1}", myRoute.direction, myRoute.distance);
Console.ReadKey();
}
}
}
However the book doesn't explain a few of the things to do with this which I do not understand.
The first part is this line:
Code:
int myDirection = -1;
declaring myDirection as an int and giving it a value of -1, however when I change this number to 0 or 7 or 3 I still get the application to function in the same way. Is this number value an x number?
There is a do while loop in there which acts as validation ensuring that myDirection can only be a value of 1-4 which is why I think that -1 is an x number but I want to check as they don't specify.
Because if it is then shouldn't you just have:
as this seems to work as well?