Chance of 12hr to 24hr | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Chance of 12hr to 24hr

Hello :) i have to chance a 12hr to 24hr ,for example 1:00PM to 13:00 This is my code: string a = Console.ReadLine(); string[] b1 = {"12","13","14","15","16","17","18","19","20","21","22","23"}; string[] b2 = {"12","1","2","3","4","5","6","7","8","9","10","11"}; string[] c = {"",":",""}; string d = ""; c[0] = a.Substring(0,a.IndexOf(":")); a = a.Replace(c[0] + ":",""); if (a.Contains("PM")){ for(int i = 0; i < b2.Length; i++){ if(c[0] == b2[i]){ c[0] = b1[i]; break; } } } a = a.Replace("PM",""); a = a.Replace("AM",""); c[2] = a; d = c[0] + c[1] + c[2]; Console.WriteLine(d); but i have a little problem When i m in the “practice your program “ i fail 2/5 of the case ... Can you help me?

10th Aug 2020, 4:20 PM
Wilkin Trinidad
Wilkin Trinidad - avatar
1 Answer
0
It is better to save code and share link... But it seems that your program shloud output 00:00 AM for input 12:00 AM and for single digit input of hour like 1:00 AM, you should output 01:00 https://www.sololearn.com/post/75089/?ref=app
10th Aug 2020, 4:58 PM
Jayakrishna 🇮🇳