Answer to Question #334703 in C# for Siyanda

Question #334703

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.


1
Expert's answer
2022-04-28T13:22:04-0400
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!");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS