Program to check an item's price against available credit This is a working program to check an item's price against available credit. I'm trying to simplify this program to the bare minimum. It would require to run so I'll be better able to understand each part of the 'if' and 'else' processes. Is there a simpler way to write a program that accomplishes the task below? I'm new to C#, just trying to figure this stuff out.


  Write a program named CheckCredit that prompts users to enter a purchase price for an item.
  If the value entered is greater than a credit limit of $8,000, display you have exceeded the credit limit; otherwise, display Approved.


using static System.Console;

namespace CheckCredit
{
    class Program
    {
        static void Main(string[] args)
        {
            const double CreditCheck = 8000;
            string userInput;
            double price;

            WriteLine("This is a program designed to check an item's price 
            against your amount of available credit.");
            WriteLine("Your credit limit is $8,000.00.\n");

            do
            {
                Write("Please type the item's price:");
                userInput = ReadLine();
                if (!double.TryParse(userInput, out _))
                {
                    WriteLine("Invalid input, please enter a whole or decimal number.");
                    userInput = null;
                }
            } while (!double.TryParse(userInput, out price));

            if (price &gt; CreditCheck)
            {
                WriteLine(" You have exceeded the credit limit", price);
            }

            else if
            (price == CreditCheck)
            {
                WriteLine(
                "Approved.(*)\n\n\n"
                +
                "(*) It is exactly your credit limit.");
            }
            else
            {
                WriteLine("Approved.");
            }
            ReadKey();
        }
    }
}
Since you are a beginner, I will try to go easy on you.  That said, this looks very beginner-ish.

As noted in the comments above, you inadvertently put a line break which causes a compiler error.  There are many here you would CLOSE the question on that alone.

Beginner's frequently use double for binary floating point values.  However, anytime you are working with money or currency, then you should use Decimal.  Decimal is floating point as well but it's Base 10 rather than Base 2.

The static import of System.Console may be allowed but in general is frowned upon.  My eyes would rather see Console.WriteLine instead of WriteLine due to over dozen years of writing .NET apps.

Naming is important.  CreditCheck is a bad name.  It should be creditLimit or currentBalance if not simply balance.  But "Check" is an action verb and it would be a method that would perform that checking action, not a variable.  Note too that for local variable naming I am using camelCase.

Organization is less than desired.  Beginners will frequently put everything in Main method.  How about you create a separate method and pass the credit limit as an argument to it?  Or even a method that accepts the credit limit and item price?

You get to decide whether such a method should return a bool to denote you have sufficient funds, or perhaps return the remaining funds after the price.  If it returned remaining funds, you now have extra information, such as negative value denotes insufficient funds (that it the price check failed).

I don't think you need a special check for price == CreditCheck.  Nice of you to throw in something extra, but why not tell them "Approved.  Remaining funds = ?".

You use decent indentation and nice that braces are wrapped around one line of code.

Why fix the credit to 8000?  Again, pass it as an argument.  If you do that, you should see why it's wrong that you hardcode it with:

WriteLine("Your credit limit is $8,000.00.\n");

I get that you want a blank line to appear after that.  For some people "\n" is perfectly acceptable.  Others would recommend using Environment.NewLine.  Putting many suggestions together, and using String Interpolation, this would become:

Console.WriteLine($"Your credit limit is ${creditLimit.ToString("N2")}.{Environment.NewLine}");

Or you could issue a simple Console.WriteLine(); to avoid the whole "\n" versus NewLine debate.