
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Given Time into Words in C++
In this tutorial, we will be discussing a program to convert given time into words. For this we will be provided with a specific time in the digital format.Our task is to convert that particular time into words
Example
#include <bits/stdc++.h> using namespace std; //printing time in words void convert_time(int h, int m){ char nums[][64] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine","ten", "eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen","eighteen", "nineteen", "twenty", "twenty one","twenty two", "twenty three", "twenty four","twenty five", "twenty six", "twenty seven","twenty eight", "twenty nine", }; if (m == 0) printf("%s o' clock\n", nums[h]); else if (m == 1) printf("one minute past %s\n", nums[h]); else if (m == 59) printf("one minute to %s\n", nums[(h % 12) + 1]); else if (m == 15) printf("quarter past %s\n", nums[h]); else if (m == 30) printf("half past %s\n", nums[h]); else if (m == 45) printf("quarter to %s\n", nums[(h % 12) + 1]); else if (m <= 30) printf("%s minutes past %s\n", nums[m], nums[h]); else if (m > 30) printf("%s minutes to %s\n", nums[60 - m],nums[(h % 12) + 1]); } int main(){ int h = 8; int m = 29; convert_time(h, m); return 0; }
Output
twenty nine minutes past eight
Advertisements