Constraints for number of animals placed (when option two is selected)

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Validating options

This is code from the Main section of the program, the original use console.writeline followed by a line to convert the input and store it in the variable. The code below wraps each of these into a do..while loop. The condition as a lower and an upper range:

 1 if ((MenuOption == 1) || (MenuOption == 2))
 2 {
 3 	if (MenuOption == 1)
 4 	{
 5 		LandscapeSize = 15;
 6 		InitialWarrenCount = 5;
 7 		InitialFoxCount = 5;
 8 		Variability = 0;
 9 		FixedInitialLocations = true;
10 	}
11 	else
12 	{
13 		do
14 		{
15 			Console.Write("Landscape Size: ");
16 			LandscapeSize = Convert.ToInt32(Console.ReadLine());
17 		}
18 		while (LandscapeSize <= 5 || LandscapeSize >= 20);
19 
20 		do
21 		{
22 			Console.Write("Initial number of warrens: ");
23 			InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
24 		}
25 		while (InitialWarrenCount <= 0 || InitialWarrenCount >= 20);
26 
27 		do
28 		{
29 			Console.Write("Initial number of foxes: ");
30 			InitialFoxCount = Convert.ToInt32(Console.ReadLine());
31 		}
32 		while (InitialFoxCount<=0||InitialWarrenCount>=20);
33 
34 		do
35 		{
36 			Console.Write("Randomness variability (percent): ");
37 			Variability = Convert.ToInt32(Console.ReadLine());
38 		}
39 		while (Variability <= 0 || Variability >= 100);
40 
41 		FixedInitialLocations = false;
42 	}
43 }