66Mhz
66Mhz

Reputation: 225

How to create method without returning any value

I'm trying to create a method where I can pass a float, evaluate it, then update a text label accordingly. Would someone be kind enough to take a look at my code and point me in the right direction? Many thanks in advance...

public static GetGrade(float wp)
    {
        if (wp >= 100)
        {
            grade_current.Text = "A";
        }
        else if (wp >= 90)
        {
            grade_current.Text = "A";
        }
        else if (wp >= 75 && wp <= 89)
        {
            grade_current.Text = "B";
        }
        else if (wp >= 60 && wp <= 74)
        {
            grade_current.Text = "C";
        }
        else if (wp >= 50 && wp <= 59)
        {
            grade_current.Text = "D";
        }
        else
        {
            grade_current.Text = "F";
        }
    }

I'm trying to call the method with GetGrade(wp);

Upvotes: 0

Views: 369

Answers (2)

Lightor
Lightor

Reputation: 493

Just use 'void', also you can clean up the code a bit to make it easier on the eyes:

public static void GetGrade(float wp)
{
    if (wp >= 100)
        grade_current.Text = "A";
    else if (wp >= 90)
        grade_current.Text = "A";
    else if (wp >= 75)
        grade_current.Text = "B";
    else if (wp >= 60)
        grade_current.Text = "C";
    else if (wp >= 50)
        grade_current.Text = "D";
    else
        grade_current.Text = "F";
}

Upvotes: 3

demoncodemonkey
demoncodemonkey

Reputation: 11957

Your method is missing a return type. If you don't need to return anything then just use "void".

public static GetGrade(float wp)

=>

public static void GetGrade(float wp)

Upvotes: 2

Related Questions