I wrote this code in c to convert normal time to military time is there anything i can do to make it simpler ? please help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I wrote this code in c to convert normal time to military time is there anything i can do to make it simpler ? please help me

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

16th May 2020, 8:02 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
24 Answers
+ 2
12:30 AM outputs 0:30 should be 00:30
16th May 2020, 8:23 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Yeah I fixed it šŸ˜… ,...anything else sir?
16th May 2020, 8:24 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
+ 1
I Fixed that siršŸ˜ šŸ‘thank you, ... Can i make it any simpler šŸ˜…?
16th May 2020, 9:08 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
+ 1
Ok i will give it a try but it's 3:00 am over here in India ,.. so i guess I will do it after I wake up šŸ˜Š thanks for answering sir
16th May 2020, 9:18 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
+ 1
The code coach input for this challenge will gives the same format consistently. Where there aren't any leading zeros and there is always a space between AM or PM which are always capitalized. I'm sure you could reduce your code by using built in functions etc, but that's up to you. I would however suggest avoiding the use of goto. Instead put that code in a function and call it.
16th May 2020, 9:19 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Ok sir thank you very much for the advice šŸ˜ŠšŸ˜Š
16th May 2020, 9:21 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
+ 1
Check this code i think it works(i checked several variants) and it is a little bit smaller then yours)))) https://code.sololearn.com/cKJHCiv4vSzG/?ref=app
16th May 2020, 9:53 PM
george
george - avatar
+ 1
https://code.sololearn.com/c9wa4CZXUC0F/?ref=app You may try checking this out.
18th May 2020, 12:52 PM
Hima
Hima - avatar
+ 1
I've done it without including <string.h>. You can check this out šŸ™ƒ https://code.sololearn.com/c4CcaO3nT71N/?ref=app
25th May 2020, 11:04 AM
Mahdee Mohammad
Mahdee Mohammad - avatar
0
Proble! Woth entering a lower case pm
16th May 2020, 9:05 PM
george
george - avatar
0
There are a lot of other cases to check 02:30pm, 02:30 pm, 2:30pm, 2:30 pm also with am
16th May 2020, 9:13 PM
george
george - avatar
0
But such checks gives possibility to think in scope of writing production code. And such experience is very usefull in future
16th May 2020, 9:22 PM
george
george - avatar
0
Yes it can be simplified. But i do not remember c function since i wrote on c++ you need just parse full str via scanf with 2 integer and 1 string param. analyze am or pm(make upper the string and check on A or P) and make manipulation i thin +12 or -12 just math calculation need
16th May 2020, 9:23 PM
george
george - avatar
0
Wow iam new to programing and I learnt a lot from your code siršŸ˜² thank you very much ,.. I'll try to make my codes more efficient from now onšŸ˜€ have a nice day ,... Happy coding šŸ˜
17th May 2020, 5:08 AM
raja mourya simha reddy
raja mourya simha reddy - avatar
0
Turns out I was just over complicating things šŸ¤¦šŸ»ā€ā™‚ļø ,.. thanks for sharing this code šŸ˜ŠšŸ˜Š
18th May 2020, 12:57 PM
raja mourya simha reddy
raja mourya simha reddy - avatar
0
Hima, good code, but you you have not some checks on correction!!!! As example is ok, but in comercial writing such code not aproved via qa department
18th May 2020, 1:07 PM
george
george - avatar
0
So always try write codes with all possible check for future.
18th May 2020, 1:07 PM
george
george - avatar
0
george what you really meant by "checks"? The code is meeting all the required conditions.
18th May 2020, 1:11 PM
Hima
Hima - avatar
0
Hima enter the 12:30 without am and pm!!!! enter 06:20 pm (small symbols) this checks need to be take to an account. so in general code is good in all aspects if you enter correct AM/PM time, and for example,ot is great but in comercial writing such code will not be approved by QA department.
18th May 2020, 1:13 PM
george
george - avatar
0
george Why should one do that in the first place ? The code is in accordance with the Input format and this is just wise thinking and making use of format specifiers at its best .
18th May 2020, 1:16 PM
Hima
Hima - avatar