a) Write a method GetOneStudent that asks a student for both of his/her WRAV101 and
WRSC111 marks (each as a real number). The method must return both of these marks. The
method must ensure that each of the marks is in the range 0 to 100.
b) Write a method CanContinue that takes as input two marks, one for WRAV101 and one for
WRSC111. Each of these marks is in the range 0 to 100. The method must return the value
true if both of these marks are at least 50, otherwise the method must return the value false.
class Program
{
static void Main()
{
(int WRAV101, int WRSC111) = GetOneStudent();
bool canContinue = CanContinue(WRAV101, WRSC111);
}
static (int WRAV101, int WRSC111) GetOneStudent()
{
return (Read("Enter the WRAV101 mark (0-100): "),
Read("Enter the WRAV101 mark (0-100): "));
}
static bool CanContinue(int WRAV101, int WRSC111)
{
return new int[] { WRAV101, WRSC111 }.All(m => m >= 50);
}
static int Read(string message, int min = 0, int max = 100)
{
while (true)
{
Console.Write(message);
if (int.TryParse(Console.ReadLine(), out int result) &&
result >= min && result <= max)
return result;
Console.WriteLine("Incorrect value of mark, pleae, try again!");
}
}
}
Comments
Leave a comment