Friday, March 21, 2014

Method_Ex_5 (Wk-8) Feb 24-28, 2014

Q: Compute the total cost of "Purchasing an item". Request number of items purchased. Request price per item. Write a method that takes number of items and price per item. Compute total cost (including tax). Return total cost.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Method_5
{
    class Program
    {
        static void Main(string[] args)
        {   double n, p;
            Console.Write("Enter number of item: ");
            double.TryParse(Console.ReadLine(), out n);

            Console.Write("Enter price per item: ");
            double.TryParse(Console.ReadLine(), out p);

            double total = TotalCost(n, p);
            string totalamount = String.Format("Total Cost = {0:c}", total);
            DisplayResult(totalamount);

            Console.ReadKey();
        }
        static double TotalCost(double n, double p)
        {
            double t = 0.098;
            double totalcost = ((n * p) + ((n * p) * t));
            return totalcost;
        }
        static void DisplayResult(string s)
        {
            Console.WriteLine("\n*************************");
            Console.WriteLine(s);
            Console.WriteLine("\n*************************");
        }
    }
}

No comments:

Post a Comment