+ 1

Problem in new driver's license challenge

This code fails in case 3 and 5 I solved the problem using for loop but I think this code is correct too Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { private static void Main() { string name = Console.ReadLine(); int agentsnumber = int.Parse(Console.ReadLine()); string others = Console.ReadLine(); List<string> names = others.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries).ToList(); names.Add(name); names.Sort(); Console.WriteLine(names.IndexOf(name) + 1); float index= (float)(names.IndexOf(name) + 1) / agentsnumber; Console.WriteLine(Convert.ToInt32(index)*20); } } } Can any one tell me where I am wrong ? Thankyou in advance

3rd May 2020, 2:53 PM
Younes Abdo
Younes Abdo - avatar
2 Answers
+ 1
Use Math.Ceiling instead of Convert.ToInt32 in your output. Console.WriteLine(Math.Ceiling(index)*20); Convert.ToInt32 rounds up and down. You need up, because you have to wait no matter how many others are in your time slot.
3rd May 2020, 3:10 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
0
Thank you for your quick answer
3rd May 2020, 3:23 PM
Younes Abdo
Younes Abdo - avatar