Start New Discussion within our Software Development Community

I have a cart that shows product selected and the quantity and the price for each. What I am wondering is how to display the price for each as well as the total for all? Here is my code...Is there a way to do this in the public string Display()...what I am trying dosesn't work.
I am tring to get the output of Product.Name (2 @ $79.99 each), to look like
Product.Name (2 @ $79.99 each = $159.98)

public class CartItem
{
    public CartItem() {}

    public CartItem(Product product, int quantity)
    {
        this.Product = product;
        this.Quantity = quantity;
    }

    public Product Product { get; set; }
    public int Quantity { get; set; }

    public void AddQuantity(int quantity)
    {
        this.Quantity += quantity;
    }

    public string Display()
    {
        string displayString = 
            Product.Name + " (" + Quantity.ToString()
            + " at " + Product.UnitPrice.ToString("c") + " each" + " =" + (Quantity * Product.UnitPrice("c"));

        return displayString;
    }


    public void AddQuantity(Product selectedProduct, int p)
    {
        throw new System.NotImplementedException();
    }

Oops, I figured it out. I didn't think about what I was trying to do. I now changed my code to look like this and everything now works.

public string Display()
    {
        decimal totalPrice = Quantity * Product.UnitPrice;
        string displayString = 
            Product.Name + " (" + Quantity.ToString()
            + " at " + Product.UnitPrice.ToString("c") + " each = " + totalPrice.ToString("c");

        return displayString;
    }
This question has already been answered. Start a new discussion instead.