VISUAL C#: 10 points best answer for anyone who will give me the answer to my question?

I will give 10 points to the first come first serve best answer (code) that answers this question correctly. Visual C# Express 2010

Question:

Design a function to determine the cost of mailing a package. Your function should expect the weight of the package to be passed as a parameter. Using this weight will permit the function to return a value that will reflect the cost of the mailing. You must use the following to determine the cost:

Packages weighinh less than 8 grams will cost .32

Packages weighing more than 8 grams and less than or equal to 12 will cost .47

Packages weighing more than 12 grams and less than or equal to 16 will cost .62

Packages weighing more than 16 grams and less than or equal to 20 will cost .77

Packages weighing more than 20 grams and less than or equal to 24 will cost .92

Packages weighing more than 24 -> Display Message "Too heavy" and cost 0.

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Function CostOfMailingApackage ( ByVal WeightOfThePackage As Double ) As Double

    Select Case WeightOfThePackage

    Case Is < 8

    CostOfMailingApackage =WeightOfThePackage * .32

    Case 8 To 12

    CostOfMailingApackage =WeightOfThePackage * .47

    Case 13 To 16

    CostOfMailingApackage =WeightOfThePackage * .62

    Case 17 To 20

    CostOfMailingApackage =WeightOfThePackage * .77

    Case 21 To 24

    CostOfMailingApackage =WeightOfThePackage * .92

    --------------------------------------------------------------------------------------

    Case Else

    CostOfMailingApackage= 0.00

    --------------------------------------------------------------------------------------

    End Select

    End Fucntion

    Because this answer is not in C#, which won't give me any points. Here is more work for you to do, but the main function is done through VB which isn't far off the logic use,but the syntactical use of C#.

    The line:

    "Packages weighing more than 24 -> Display Message "Too heavy" and cost 0."-shouldn't be included as part of the implementation of this Function.

    This doesn't mean it is not possible. Just more unnecessary codes to write. For one, now you are dealing with more different data types in this one function. Instead of just the "double-data type" which is of the parameter and the returned type, now you have an additional data of "string data-type" to manipulate (data-conversion).

    The best place to put the codes that govern that criteria is from the source object that will be gathering inputs from the users to be used as parameters to this function. That input object can validate and check that the values entered were not over a certain limit and if so execute a code that shows a message box saying "Too heavy". Note I did not format the return value of the function to its dollar sign.

    I added this (separated by -----) code to the end of the Select code block in case you need it. It will return a value of 0 which to you ( only, who knows about the implementations of this function) means that the value send in by the user as a parameter must have been over 24.

  • m b
    Lv 5
    8 years ago

    public static string priceoffmail(int weightingrams)

    {

    if (weightingrams <8)

    { return "0.32"}

    else if (weightingrams >8 && weightingrams <= 12)

    { return "0.47"}

    else if (weightingrams >12 && weightingrams <= 16)

    { return "0.62"}

    etc etc all way down and last 1

    else if(weightingrams >24)

    {return "to heavy"}

    }

    Source(s): this was done with out ide so spelling may need to be checked but besides that thats a function to do it that returns values as strings in u need to convert it to double or decicimal use the system.convert lib
Still have questions? Get your answers by asking now.