비즈니스 규칙 적용 과제 작업에 대한 솔루션 검토

완료됨

다음 코드는 이전 단원의 과제에 사용 가능한 해결 방법 중 하나입니다.

Random random = new Random();
int daysUntilExpiration = random.Next(12);
int discountPercentage = 0;

if (daysUntilExpiration == 0)
{
    Console.WriteLine("Your subscription has expired.");
}
else if (daysUntilExpiration == 1)
{
    Console.WriteLine("Your subscription expires within a day!");
    discountPercentage = 20;
}
else if (daysUntilExpiration <= 5)
{
    Console.WriteLine($"Your subscription expires in {daysUntilExpiration} days.");
    discountPercentage = 10;
}
else if (daysUntilExpiration <= 10)
{
    Console.WriteLine("Your subscription will expire soon. Renew now!");
}

if (discountPercentage > 0)
{
    Console.WriteLine($"Renew now and save {discountPercentage}%.");
}

많은 것이 로직 구현 결정 방법에 종속되기 때문에 이 코드는 단지 “가능한 솔루션의 하나”일 뿐입니다. 과제의 규칙에 따라 올바른 결과를 얻었고 두 if 문을 사용했다면 아주 잘하신 것입니다.

성공했다면 축하합니다! 다음 단원의 지식 점검을 계속 진행하세요.

중요

이 과제를 완료하는 데 문제가 있는 경우 계속 진행하기 전에 이전 단원을 복습해야 할 수도 있습니다.