C
C#13mo ago
Luke Dimond

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
Angius
Angius13mo ago
5, 1, and 0 are all <= 10 So it sees "aight, it's less than 10, execute this clause"
Luke Dimond
Luke DimondOP13mo ago
ahhhh, so could i do if (daysUntilExpiration <= 10 && daysUntilExpiration > 5) to fix it?
Angius
Angius13mo ago
Exactly like this
Luke Dimond
Luke DimondOP13mo ago
Thank you.
Angius
Angius13mo ago
Or you could reverse the order
Luke Dimond
Luke DimondOP13mo ago
I see, so it checks the lower values first
Angius
Angius13mo ago
It checks in order, top to bottom
Luke Dimond
Luke DimondOP13mo ago
Thanks
AdiZ
AdiZ13mo ago
@Luke Dimond I recognize this from Programming... Codecademy?
Want results from more Discord servers?
Add your server