In: Computer Science
C# assignment 5: Shipping Charges
A large Internet merchandise provider determines its shipping
charges based on the number of items purchased. As the number
increases, the shipping charges proportionally decrease. This is
done to encour- age more purchases. If a single item is purchased,
the shipping charge is $2.99. When customers purchase between 2 and
5 items, they are charged the initial $2.99 for the first item and
then $1.99 per item for the remaining items. For customers who
purchase more than 5 items but less than 15, they are charged the
initial $2.99 for the first item, $1.99 per item for items 2
through 5, and $1.49 per item for the remaining items. If they
purchase 15 or more items, they are charged the initial $2.99 for
the first item, $1.99 per item for items 2 through 5, and $1.49 per
item for items 6 through 14, and then just $0.99 per item for the
remaining items. Allow the user to enter the number of items
purchased. Define appropriate constants, use the decimal data type,
and display the ship- ping formatted charges.
C# Code:
using System;
class Program
{
   //Defining constants
    public const double item_1 = 2.99;
    public const double item_2_5 = 1.99;
    public const double item_6_14 = 1.49;
    public const double item_15 = 0.99;
  
   //Main method
    static void Main()
    {
        int numItems;
        double shippingCharges =
0.0;
      
        //Reading number of
items
        Console.Write("Enter
number of items purchased: ");
        numItems =
Convert.ToInt32(Console.ReadLine());
      
       //For single item
        if (numItems == 1)
        {
           
shippingCharges = item_1;
        }
      
       //Items greater than 1 and less
than or equal to 5
        else if (numItems > 1
&& numItems <= 5)
        {
           
shippingCharges = item_1 + ((numItems-1) * item_2_5);
        }
      
       //Items greater than 5 and less
than or equal to 14
       else if (numItems > 5 &&
numItems < 15)
        {
           
shippingCharges = item_1 + (item_2_5*4) +
((numItems-5)*item_6_14);
        }
      
       //Items greater than or equal to
15
       else if (numItems >= 15)
        {
           
shippingCharges = item_1 + (item_2_5 * 4) + (item_6_14 * 9) +
((numItems - 14) * item_15);
        }
      
       //Printing result
       Console.Write("\nShipping Charges:
${0:F2}", shippingCharges);
    }
}
_____________________________________________________________________________________________
Sample Run:
