1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{
string ones[21]= {" ", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
string tens[10]= {"ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
int num, ret, left, right, hundredth;
int a,b,c,d,e,f,g;
while(num!=0)
{
cout<<endl<< "Enter a number between -9999999 and 9999999, o to exit: \n"<<endl;
cin>>num;
system("CLS");
cout<<endl;
while(num<-9999999 || num>9999999)
{
cout<< "The number you enter is too high! Please enter the exact number: \n";
cout<<endl;
cin>>num;
system("CLS");
}
a= (num%10000000)-(num%1000000); //million
b= (num%1000000)-(num%100000); //hundred thousand
c= (num%100000)-(num%10000); //ten thousand
d= (num%10000)-(num%1000); //thousand
e= (num%1000)-(num%100); //hundred
f= (num%100)-(num%10); //ten
g= num%10;
if(num<0)
{
cout<< "negative";
}
if(num>=1000000)
{
ret= a/1000000;
cout<<ones[ret]<< " "<<" million ";
}
if(num>=100000)
{
ret= b/100000-1;
right= c/10000;
hundredth= b/100000;
cout<<ones[hundredth]<<" hundred ";
}
if(num>=10000 && num<20000)
{
ret= (c+d)/1000;
cout<<ones[ret]<< " ";
}
else if(num>=100000)
{
right= c/10000-1;
left= d/1000;
cout<<tens[right]<< " "<<ones[left]<<" ";
}
if(num>=1000 && num<10000)
{
ret= d/1000;
cout<<ones[ret]<< " ";
}
if(num>=1000)
{
cout<< " thousand ";
}
if(num>=100)
{
ret= e/100;
cout<<ones[ret]<< " "<< " hundred ";
}
if(num>=20)
{
left= f/10-1;
right= g;
cout<<tens[left]<<" "<<ones[right];
}
else if(num<20 || num>0)
{
ret= f+g;
cout<<ones[ret];
}
cout<<endl;
}
return 0;
}
|