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
|
#include <iostream>
#include <string>
#include <math.h>
#ifndef NUMBERS_H
#define NUMBERS_H
using namespace std;
class Numbers
{
private:
int number;
public:
Numbers(int x)
{
num = x;
}
void print();
};
void Numbers::print()
{
int n;
int num;
string lessThanTwenty[20] = { " ", "One", "Two", "Three", "Four", "Five" "Six", "Seven", "Eight",
"Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string tens[] = { "zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty" };
string hundreds = { " ", "Hundred" };
string thousands = { " ", "Thousand" };
if (num < 0)
cout << "Number is a negative number. Please enter a number between 0-9999.";
num = abs(num);
n = num / 1000;
if (n>0)
cout << lessThanTwenty[n] << thousands;
num %= 1000;
n = num / 100;
if (n > 0)
cout << lessThanTwenty[n] << hundreds;
num %= 100;
if (num >= 20)
{
n = num / 10;
if (n > 0)
cout << tens[n] << " ";
}
else if (num >= 10)
{
cout << lessThanTwenty[num] << " ";
return;
}
num %= 10;
if (num > 0)
cout << lessThanTwenty[num];
cout << " ";
};
#endif
|