Answer to Question #200489 in C# for Wise Tshikovhela

Question #200489

Create a program whose Main() method prompts a user for length and width of a room in meter. Create a method that accepts the values and then computes the estimated cost of painting the room, assuming the room is rectangular and has four full walls and the walls are 2.6 meter high. The rate for the painting job is R20 per square meter.


Return the estimated cost to the Main() method, and display it.


Write a user defined method named getMark that can be used to get a valid mark from the user. Your method must continuously ask the user for a mark, until a valid mark is entered (valid marks are between 0 and 100). If a user enters an invalid mark, display an error message before asking for a valid mark to be entered. The method must return the valid value to the calling program.


Write a user defined method named isPass that can be used to determine whether a mark is a pass mark (greater or equal to 50). The method must take as input a mark, and return a boolean, indicating whether the mark was a pass mark.


1
Expert's answer
2021-05-30T07:11:02-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q200489
{
    class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            double length;
            double width;
            Console.Write("Enter the length of a room: ");
            double.TryParse(Console.ReadLine(), out length);
            Console.Write("Enter the width of a room: ");
            double.TryParse(Console.ReadLine(), out width);
            //Return the estimated cost to the Main() method, and display it.
            Console.WriteLine("\nThe estimated cost of painting the room is R{0}\n", computeEstimatedCost(length, width));


            Console.ReadLine();
        }
        /// <summary>
        ///  Create a method that accepts the values and then computes the estimated cost of painting the room, assuming the room is 
        ///  rectangular and has four full walls and the walls are 2.6 meter high. The rate for the painting job is R20 per square meter.
        /// </summary>
        /// <param name="length"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        static double computeEstimatedCost(double length, double width)
        {
            return 2 * ((length * 2.6) + (width * 2.6)) * 20.0;
        }
    }
}








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


namespace Q200489
{
    class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {


            for (int mark = 0; mark < 5; mark++) {
                //get mark from the user
                int userMark = getMark();
                //Check if mark is pass
                if (isPass(userMark))
                {
                    Console.WriteLine("The mark is pass\n");
                }
                else {
                    Console.WriteLine("The mark is not pass\n");
                }
            }


            Console.ReadLine();
        }
        /// <summary>
        ///  Defined method named getMark that can be used to get a valid mark from the user. 
        ///  Your method must continuously ask the user for a mark, until a valid mark is entered (valid marks are between 0 and 100). 
        ///  If a user enters an invalid mark, display an error message before asking for a valid mark to be entered. 
        ///  The method must return the valid value to the calling program.
        /// </summary>
        /// <returns></returns>
        static int getMark() {
            int userMark =-1;
            while (userMark < 0 || userMark > 100)
            {
                Console.Write("Enter the mark: ");
                if (!int.TryParse(Console.ReadLine(), out userMark))
                {
                    Console.WriteLine("Error: valid marks are between 0 and 100. Try again.\n");
                    userMark = -1;
                }
            }
            return userMark;
        }
        /// <summary>
        ///  Defined method named isPass that can be used to determine whether a mark is a pass mark (greater or equal to 50). 
        ///  The method must take as input a mark, and return a boolean, indicating whether the mark was a pass mark.
        /// </summary>
        /// <param name="mark"></param>
        /// <returns></returns>
        static bool isPass(int mark)
        {
            if (mark >=50) {
                return true;
            }
            return false;
        }


    }
}




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
APPROVED BY CLIENTS