Solution: Retail Discount Calculator

Review the implementation of the TryParse pattern and relational patterns to create a crash-resistant retail calculation tool.

Solution: Retail Discount Calculator

Review the implementation of the TryParse pattern and relational patterns to create a crash-resistant retail calculation tool.
Console.WriteLine("=== Retail Discount Calculator ===");

Console.Write("Enter the original price: ");
string input = Console.ReadLine();

// We use double.TryParse to allow for decimal prices
if (double.TryParse(input, out double price))
{
    // Apply 15% discount if price is 100 or more
    double finalPrice = (price >= 100) ? price * 0.85 : price;

    Console.WriteLine($"Original Price: ${price}");
    Console.WriteLine($"Final Price: ${finalPrice}");
}
else
{
    Console.WriteLine("Error: Please enter a valid numeric price.");
}
The complete solution for the retail discount calculator exercise