dorlox
dorlox

Reputation: 75

Value type string cannot be used as default parameter

class Program
{
    static void Main(string[] args)
    {

        Console.WriteLine("Tuition is {0}", CalculateTuition(15, false, '0')); // didn't fill all parameters
        Console.WriteLine("Tuition is {0}", CalculateTuition(15, false, 'O')); // didn't fill all parameters
        Console.WriteLine("Tuition is {0}", CalculateTuition(15, true, '0'));
    }
    public static double CalculateTuition(double credits, bool scholarship = false, char code = "I") // added double for return type
    {
        double tuition;
        const double RATE = 80.00;
        const double OUT_DISTRICT_FEE = 300.00;
        tuition = credits * RATE;
        if (code == 'I')
            tuition += OUT_DISTRICT_FEE;
        if (scholarship)
            tuition = 0;
        return tuition;
    }
}

I don't understand how to fix the error A value of type 'string' cannot be used as a default parameter because there are no standard conversions to type 'char' I tried looking up the code solution but I don't really understand how to fix this...

Upvotes: 1

Views: 538

Answers (1)

Matt
Matt

Reputation: 13349

You need to use single-quote '' for char literals:

public static double CalculateTuition(double credits, bool scholarship = false, char code = 'I')

Upvotes: 7

Related Questions