
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- C++ program to convert all digits from the given range into words
- PHP program to convert a given timestamp into time ago
- C Program to convert a given number to words
- How to convert integers into integers written in words in R?
- Split the sentence into words in C++
- What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time in C#?
- Python program to convert local time into GMT
- C# program to join words into a string in C#
- C# Program to convert Digits to Words
- C program to convert digit to words
- Reverse words in a given String in C#
- Count words in a given string in C++
- How to convert UTC date time into local date time using JavaScript?
- Python - Convert given list into nested list
- How to convert date and time into int in Android sqlite?

Advertisements