Converting Numbers into their Words Equivalent in C++

#include <iostream>
#include <string.h>
#include <string>
using namespace std;
/*
The program converts a number to its word equivalent.
For example, 1 One ,2 -> two ,3 -> three .............

*/

unsigned long long int Denominations[] = {1000000000000000000,1000000000000000,
1000000000000,1000000000,1000000
,1000,100,1};
const int No_Of_Denums = sizeof(Denominations)/sizeof(long long int);
char Ones[] = {"zero","one ","two ","three ","four ","five ","six ",
"seven ","eight ","nine "};
char Tens[] = {"twenty ","thirty ","forty ","fifty ","sixty ",
"seventy ","eighty ","ninety "};
char Scale[] = {"hexillion ","quintillion ","quadrillion ","trillion ","billion ","million ",
"thousand ","hundred ",""};
char Teens[] = {"ten ","eleven ","twelve ","thirteen ",
"fourteen ","fifteen ","sixteen ","seventeen ","eighteen "
,"nineteen "};
string UnderHundred(int n)
{
// n is known to be under 1000. Hence first split up it into 3 numbers
int n1,n2,n3;
n1=n%10; n/=10;
n2=n%10; n/=10;
n3=n%10;
string s="";
if (n3!=0)
{
s+=Ones[n3];
s+="hundred ";
}
if (n2!=0)
{
if (n2==1)      //Different construction for Teens, ten inclusive
{
s+=Teens[n1];
return s;
}
s+=Tens[n2-2];
s.replace(s.length()-1,1,"-");
}
s+=Ones[n1];
return s;
}
string Words(unsigned long long int n)
{
int DenumCount[No_Of_Denums] = {0};
int DenumPointer=0;
while (true)
{
if (n < Denominations[DenumPointer])
{
DenumPointer++;
if (DenumPointer>=No_Of_Denums)
{
break;
}
continue;
}
DenumCount[DenumPointer]++;
n-=Denominations[DenumPointer];
}
string s="";
//Now create a string on the basis of those values
for (int i=0;i<No_Of_Denums;i++)
{
if (DenumCount[i]==0) continue;
s+=UnderHundred(DenumCount[i]);
s+=Scale[i];
}
//Convert to first letter to ucase
s = toupper(s);
return s;
}
int main()
{
unsigned long long int i;
unsigned long long int Limit = 0xFFFFFFFFFFFFFFFF;
cout << "Print the number you wish to convert. (0) to exit\n";
cout << Limit <<" is the limit.\n\n";
while(true)
{
cout << "Enter a number to find the word spell\n" << endl;
cin >> i;
if (!i) break;
string s = Words(i);
cout << Words(i) << endl;
}
system("pause");
return 0;
}

---------------------------------------

c++ - Write code to convert given number into words
Converting Numbers into their Words Equivalent  C++
Write a program to convert digits into its equivalent words in C++
Convert Numbers To Words - C And C++
Spell Number: Read out a number in C++
c++ code to print possibities of a word without
C++ Program That Converts A Number Into Words
How to convert numbers to words in C++
Program to count the number of words and characters C++
C or C++ program to read a word Partner Sites

SqliteTutorials.com

Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ