+2

Military Time Problem

My code fails on case 3 and 5, can anyone tell me what's wrong with the code string[] numin = Console.ReadLine().Split(':',' '); if (numin[2].Contains('P')) { int numout = Convert.ToInt32(numin[0]); numout += 12; string numouts = Convert.ToString(numin[1]); Console.Write(numout); Console.Write(':') Console.Write(numouts[0]); Console.Write(numouts[1]); } else if (numin[2].Contains('A')) { Console.Write(numin[0]); Console.Write(':'); Console.Write(numin[1]); };

1/15/2020 7:40:14 PM

Flayer

21 Answers

New Answer

+5

OK. I missed one more.. If it single digit like 8:00 AM output should be like 08:00

+21

Notice: Single digits in left side like 8:00 00:00 am 00:00 pm 00:20 am 00:20 pm Your code must output right for these examples

+6

Paste code in code playground save code and share your code link here. That will make easy to find out errors.. For input 12:20pm your output 24:20 it should be 12:20 only..

+2

If input is 12:10am you need output 0:10 as output... If 12:05pm then you have output 12:05 only... By with your code what you getting..?

+2

OK. Fine.. Well come...

+1

Jayakrishna still nothing string[] numin = Console.ReadLine().Split(':',' '); if (numin[2].Contains('P')) { int numout = Convert.ToInt32(numin[0]); numout += 12; string numouts = Convert.ToString(numin[1]); Console.Write(numout); Console.Write(':'); Console.Write(numouts[0]); Console.Write(numouts[1]); } else if (numin[2].Contains('A')) { int bollout = Convert.ToInt32(numin[0]); if (bollout != 12) { Console.Write(numin[0]); Console.Write(':'); Console.Write(numin[1]); } else { Console.Write("00"); Console.Write(':'); Console.Write(numin[1]); } };

+1

https://code.sololearn.com/cHjX1md9oA69/?ref=app

+1

After numout value assigning change like this... And check again... if(numout!=12) numout += 12;

+1

It didn't work did it work for u?

+1

Do you changed above one.? . I done it java. Let me see description.. What is error? .

+1

It's not an error it fails the cases

+1

Yes it worked thank you https://code.sololearn.com/cHjX1md9oA69/?ref=app

+1

Flayer i faced the same problem, The problem is if the input is of single digit then we need to print output with an additional 0, I.e. 6:45 AM Op - 0645 check this, https://www.sololearn.com/Discuss/2135879/?ref=app

+1

Akash Sil I have already fixed it just do something like If input[0] < 10 write("0") before the actually result

+1

Hlo

+1

+1

There is an easier way to write this. Check it ;). https://code.sololearn.com/csvOritrsLMi

+1

DateTime is one of the things I hate the most in c# Jolanta Malinowska but thanks

0

Jolanta Malinowska you have to send a playground link not a coach cuz I can't see it

0

Flayer I just edited link. Try once again.