English Spelling can be somewhat complicated, but is ultimately guided by a set of consistent rules
English is not a phonetic language! Letters don't simply make a sound, it all depends on context.
I before E excpet after C is one of the most famous rules of English.
If the letter G appears before the vowels E I or Y, it normally is soft, although words more recenty imported into english often ignore this rule. Typically to avoid this, a u is placed after the G to insure it is hard even if followed by the E or I sound
To learn more Spelling, check out these tutorials!