Answer to Question #201127 in C# for Nkhululeko Chabala

Question #201127

Create a user defined method named calcCost() that accepts two values as input (length and width), 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. Your method should return the estimated cost to the calling method. Create a program whose Main() method prompts a user for the length and the width of a room in meter, then calls calcCost to calculate the estimated cost. Once calculated, you should display the estimated cost.


1
Expert's answer
2021-05-31T09:16:08-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q201127
{
    class Program
    {
        /// <summary>
        ///  Create a program whose Main() method prompts a user for the length and the width of a room in meter, 
        ///  then calls calcCost to calculate the estimated cost. Once calculated, you should display the estimated cost.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            float floatLength;
            float floatWidth;
            Console.Write("Enter the length of a room: ");
            floatLength = float.Parse(Console.ReadLine());
            Console.Write("Enter the width of a room: ");
            floatWidth = float.Parse(Console.ReadLine());
            Console.WriteLine("The estimated cost of painting room = R" + calcCost(floatLength, floatWidth).ToString("N"));


            Console.ReadLine();
        }
        /// <summary>
        /// Computes the estimated cost of painting the room
        /// </summary>
        /// <param name="floatLength"></param>
        /// <param name="floatWidth"></param>
        /// <returns></returns>
        static float calcCost(float floatLength, float floatWidth)
        {
            return 104.0f * (floatLength + floatWidth);
        }
    }
}




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