web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

running this code it not showing the grade proper

(0) ShareShare
ReportReport
Posted on by 371

static void switch_statement1(Args _args)
{
int score = 72;
str grade;

switch (score)
{
case (90-100) : grade = "A";
break;
case (70-89): grade = "B";
break;
default : grade = "c";
break;
}

info(strFmt("%1",grade));

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    306,118 Super User 2026 Season 1 on at

    Hi Vinay,

    90-100 seems to be a kind of calculation. You can better do it like this:

    if (score >= 90) && (score <= 100)

    {

       grade = "A";

    }

    if (score >= 70) && (score < 90)

    {

       grade = "B";

    }

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi Vinay,

    You can use approach proposed by Andre or if you don't like if..else you can go with switch using next code:

    static void switch_statement1(Args _args)
    {
        int score = 72;
        str grade;
        
        switch (true)
        {
            case (score >= 90 && score <= 100): 
                grade = "A";
                break;
            case (score >= 70 && score < 90): 
                grade = "B";
                break;
            default : grade = "c";
                break;
        }
        info(strFmt("%1",grade));
    }
  • CU02060633-1 Profile Picture
    371 on at

    Thank you @André Arnaud de Calavon but while ruuning this code there is syntex error after  && (score <= 100)

  • CU02060633-1 Profile Picture
    371 on at

    Thank you @André Arnaud de Calavon

  • CU02060633-1 Profile Picture
    371 on at

    thank you @ievgen Miroshnikov its working properly...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans