mercredi 19 juin 2019

Is there a simpler way to write this write this program? I'm a beginner in C#

I'm a beginner and need to see if this program can be simplified so I can better understand what I'm doing.

I've tried simplifying it but can't

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 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 > 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();
    }
}
}

No errors, I just think it's unnecessarily complex for an very basic 'if' or 'else' beginner program.

Aucun commentaire:

Enregistrer un commentaire