Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A large Internet merchandise provider determines its shipping charges based on t

ID: 3799420 • Letter: A

Question

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 encourage 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. Display the shipping charges.

Test data:

Number of items purchased

1

3

8

12

16

Shipping charge

$2.99

$6.97

$15.42

$21.38

$26.34

1.Allow the user to enter the number of items purchased. If the user does not enter a positive whole number, display a message “Problem with input” and assume that the number of items purchased is zero.

2. Compute the shipping charge according to the rule that is explained in the above description.

3. Display the shipping charge. If the shipping charge is zero, then display a message “Error incorrect input”.   

Using visual studio C# console application.

Number of items purchased

1

3

8

12

16

Shipping charge

$2.99

$6.97

$15.42

$21.38

$26.34

Explanation / Answer

using System;

public class CalcCost
{
static void Main(string[] args)
{   

int NumofItems = 0;
double ShippingCost = 0;
Console.Write(" Enter the number of items purchased: ");
string line = Console.ReadLine();
NumofItems = int.Parse(line);
           if(NumofItems<0){
           Console.Write(" Proble with input and assuming that the number of items purchased is zero ");
           NumofItems=0;
          
           }
if (NumofItems == 1) //1 item
{
ShippingCost = 2.99;
}
else if (NumofItems > 1 && NumofItems <= 5) //1 to 5
{
ShippingCost = 2.99 + ((NumofItems-1) * 1.99);
}
else if (NumofItems > 5 && NumofItems < 15) //6 to 14
{
ShippingCost = 2.99 + (1.99*4) + ((NumofItems-5)*1.49);
}
else if (NumofItems > 15) //more than 15
{
ShippingCost = 2.99 + (1.99 * 4) + (1.49 * 9) + ((NumofItems - 14) * 0.99);
}

/*if (NumofItems > 1)
{
if (NumofItems < 5)
{
if (NumofItems < 15)
{
if (NumofItems > 15)
{
ShippingCost = 2.99;
}
else
{
ShippingCost = (1.99 * 4) + 2.99;
}
}
else
{
ShippingCost = (1.49 * 9) + (1.99 * 4) + 2.99;
}
}
else
{
ShippingCost = (0.99) + (1.99 * 4) + 2.99;
}*/

               if (ShippingCost==0)
               Console.WriteLine("Error !! incorrect input ");
               else
Console.WriteLine(String.Format("The total ShippingCost charge for {0:f0} items is ${1:f2} ",NumofItems, ShippingCost));
}
           }
          
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote