You are viewing a single comment's thread. Return to all comments →
string timeInWords(int h, int m) { mapmp; mp[1]="one"; mp[2]="two"; mp[3]="three"; mp[4]="four"; mp[5]="five"; mp[6]="six"; mp[7]="seven"; mp[8]="eight"; mp[9]="nine"; mp[10]="ten"; mp[11]="eleven"; mp[12]="twleve"; mp[13]="thirteen"; mp[14]="fourteen"; mp[16]="sixteen"; mp[17]="seventeen"; mp[18]="eighteen"; mp[19]="nineteen"; mp[20]="twenty"; mp[40]="twenty"; mp[50]="ten"; string s=""; if(m==0){ s+=mp[h]+" o' clock"; return s; } else if(m>=1 and m<=14){ if(m==1 and h==1){ s+="one minute past one"; } else s+=mp[m]+" minutes past "+mp[h]; return s; } else if(m==15){ s+="quarter past "+mp[h]; return s; } else if(m>=16 and m<20){ s+=mp[m]+" minutes past "+mp[h]; return s; } else if(m>=20 and m<=29){ int x=m%10; s+="twenty "+mp[x]+" minutes past "+mp[h]; return s; } else if(m==30){ s+="half past "+mp[h]; return s; } else if(m>30 and m<40){ int x=60-m; x=x%10; if(h==12){ s+="twenty "+mp[x]+" minutes to one"; } else s+="twenty "+mp[x]+" minutes to "+mp[h+1]; return s; } else if(m>=40 and m<=59 and m!=45){ int x=60; if(h==12){ s+=mp[60-m]+" minutes to one"; } else s+=mp[60-m]+" minutes to "+mp[h+1]; return s; } else if(m==45){ if(h==12){ s+="quarter to one"; } else s+="quarter to "+mp[h+1]; return s; } return s; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Time in Words
You are viewing a single comment's thread. Return to all comments →
string timeInWords(int h, int m) { mapmp; mp[1]="one"; mp[2]="two"; mp[3]="three"; mp[4]="four"; mp[5]="five"; mp[6]="six"; mp[7]="seven"; mp[8]="eight"; mp[9]="nine"; mp[10]="ten"; mp[11]="eleven"; mp[12]="twleve"; mp[13]="thirteen"; mp[14]="fourteen"; mp[16]="sixteen"; mp[17]="seventeen"; mp[18]="eighteen"; mp[19]="nineteen"; mp[20]="twenty"; mp[40]="twenty"; mp[50]="ten"; string s=""; if(m==0){ s+=mp[h]+" o' clock"; return s; } else if(m>=1 and m<=14){ if(m==1 and h==1){ s+="one minute past one"; } else s+=mp[m]+" minutes past "+mp[h]; return s; } else if(m==15){ s+="quarter past "+mp[h]; return s; } else if(m>=16 and m<20){ s+=mp[m]+" minutes past "+mp[h]; return s; } else if(m>=20 and m<=29){ int x=m%10; s+="twenty "+mp[x]+" minutes past "+mp[h]; return s; } else if(m==30){ s+="half past "+mp[h]; return s; } else if(m>30 and m<40){ int x=60-m; x=x%10; if(h==12){ s+="twenty "+mp[x]+" minutes to one"; } else s+="twenty "+mp[x]+" minutes to "+mp[h+1]; return s; } else if(m>=40 and m<=59 and m!=45){ int x=60; if(h==12){ s+=mp[60-m]+" minutes to one"; } else s+=mp[60-m]+" minutes to "+mp[h+1]; return s; } else if(m==45){ if(h==12){ s+="quarter to one"; } else s+="quarter to "+mp[h+1]; return s; } return s; }