Question #39353

Create an application that determines the total due including sales tax and shipping. Allow the user to input any number of item prices. Sales tax of 7% is charged against the total purchases. Shipping charges can be determined from the following chart. Display an itemized summary containing the total purchase charge, sales tax amount, shipping charge, and grand total.
$0-$250.00 $5.00
$250.01-$500.00 $8.00
$500.01-$1000.00 $10.00
$1000.01-$5000.00 $15.00
over $5000.00 $20.00

Expert's answer

Answer to question #39353, Programming, C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Task_35657
{
    class Program
    {
        static void Main(string[] args)
        {
            string p = ReadInput();
            double[] item_prices = Parse_item_prices(p);
            if (item_prices == null)
            {
                Console.WriteLine("incorrect input");
                Console.ReadLine();
                return;
            }
            double sum = 0;
            for (int i = 0; i < item_prices.Length; i++)
            {
                sum += item_prices[i];
            }
            double shipping = Calculate_shipping(sum);
            double tax = Calculate_taxes(sum);
            Output(sum, shipping, tax);
        }
        static string ReadInput()
        {
            Console.WriteLine("enter item prices:");
            string input = Console.ReadLine();
            return input;
        }
        static void Output(double sum, double shipping, double taxes)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("======== Total purchase charge =======");
            Console.WriteLine(Math.Round(sum, 2).ToString() + " $");
            Console.WriteLine();
            Console.WriteLine("======== Sales tax amount =======");
            Console.WriteLine(Math.Round(taxes, 2).ToString() + " $");
            Console.WriteLine();
            Console.WriteLine("======== Shipping charge =======");
            Console.WriteLine(Math.Round(shipping, 2).ToString() + " $");
            Console.WriteLine();
            Console.WriteLine("======== Grand total =======");
            Console.WriteLine(Math.Round(shipping + sum + taxes, 2).ToString() + " $");
            Console.ReadLine();
        }
        static double[] Parse_item_prices(string prices)
        {
            string[] item_prices_string = prices.Split(' ');
            double[] item_prices = new double[item_prices_string.Length];
            bool success;
            int i = 0;
            do
            {
                success = false;
                success = double.TryParse(item_prices_string[i], out item_prices[i]);
                if (item_prices[i] < 0)
                    success = false;
                i++;
            }
            while (success && i < item_prices.Length);
            if (!success)
            {
                return null;
            }
            else
                return item_prices;
        }
        static double Calculate_shipping(double sum)
        {
            double shipping;
            if (sum <= 250)
                shipping = 5;
            else
                if (sum > 250 && sum <= 500)
                    shipping = 8;
                else
                    if (sum > 500 && sum <= 1000)
                        shipping = 10;
                    else
                        if (sum > 1000 && sum <= 5000)
                            shipping = 15;
                        else
                            shipping = 20;
            return shipping;
        }
        static double Calculate_taxes(double sum)
        {
            return sum * 0.07;
        }
    }
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS