No matter what number it always prints "Your subscription will expire soon. Renew now!"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace newTrain
{
internal class Program
{
static void Main(string[] args)
{
Random random = new Random();
int daysUntilExpiration = random.Next(12);
int discountPercentage = 0;
// Your code goes here
if (daysUntilExpiration <= 10)
{
Console.WriteLine(daysUntilExpiration);
Console.WriteLine("Your subscription will expire soon. Renew now!");
}
else if (daysUntilExpiration <= 5)
{
Console.WriteLine(daysUntilExpiration);
Console.WriteLine($"Your subscription expires in {daysUntilExpiration} days.\r\nRenew now and save 10%!");
}
else if (daysUntilExpiration == 1)
{
Console.WriteLine(daysUntilExpiration);
Console.WriteLine("Your subscription expires within a day!\r\nRenew now and save 20%!");
}
else if (daysUntilExpiration == 0)
{
Console.WriteLine(daysUntilExpiration);
Console.WriteLine("Your subscription has expired.");
}
else
{
}
Console.ReadLine();
}
}
}
9 Replies
5
, 1
, and 0
are all <= 10
So it sees "aight, it's less than 10, execute this clause"ahhhh, so could i do if (daysUntilExpiration <= 10 && daysUntilExpiration > 5) to fix it?
Exactly like this
Thank you.
Or you could reverse the order
I see, so it checks the lower values first
It checks in order, top to bottom
Thanks
@Luke Dimond I recognize this from Programming... Codecademy?