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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
using namespace std;
double userInput;
double number;
double fraction;
string one [21] = {"", "One" , "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine","Ten",
"Eleven", "Twelve", "Thirteen","Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
string tens [10] = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
string hun [10] = {"","Hundred", "Thousand", "Million"};
int num[10];
int frac[5];
double length = 0;
int x = 0, n = 0, a = 0, b = 0, c = 0, f = 0;
void getNumber ()
{
//getNumber gets the number and splits into three parts
//and stores it in an array
n = (int)number;
for (x = 0; x < 10; x++)
{
num[x] = n % 1000;
n = n / 1000;
}
}
void getDecimal ()
{
//getDecimal and makes it a int and stores the
//decimal in an array
if(fraction < 1 && fraction > .00)
{
fraction = fraction * 100;
f = (int)fraction;
for (x = 0; x < 4; x++)
{
frac[x] = f % 10;
f = f / 10;
}
}
}
void getToWords ()
{
//getToWords takes the number and decimal was stored in the array
//and runs through whiles statement to get the written form
x = 0;
while (x > -1)
{
if (num[2] != 0)
{
a = num[2] / 100;
if (a > 0)
{
cout << one[a] << " " << hun[1] << " ";
}
b = num[2] % 100;
if (b > 0 && b < 20)
{
cout << one[b] << " " << hun[3] << " ";
}
else
{
b = (num[2] /10)% 10;
c = (num[2] % 10);
cout << tens[b] << " " << one[c] << " " << hun[3] << " ";
}
}
x--;
}
x = 0;
while (x > -1)
{
if (num[1] != 0)
{
a = num[1] / 100;
if (a > 0)
{
cout << one[a] << " " << hun[1] << " ";
}
b = num[1] % 100;
if (b > 0 && b < 20)
{
cout << one[b] << " " << hun[2] << " ";
}
else
{
b = (num[1] /10)% 10;
c = (num[1] % 10);
cout << tens[b] << " " << one[c] << " " << hun[2] << " ";
}
}
x--;
}
x = 0;
while (x > -1)
{
a = num[0] / 100;
if (a > 0)
{
cout << one[a] << " " << hun[1] << " ";
}
b = num[0] % 100;
if (b > 0 && b < 20)
{
cout << one[b] << " ";
}
else
{
b = (num[0] /10)% 10;
c = (num[0] % 10);
cout << tens[b] << " " << one[c] << " ";
}
x--;
}
//stuck at this point as if right now
//x = 0;
//while (x > -1)
//{
// a = frac[1];
// if (a > 0)
// {
// cout << one[a] << " ";
// }
// x--;
//
//x = 0;
//while (x > -1)
//{
// b = frac[0];
// if (b > 0)
// {
// cout << one[b] << " ";
// }
// x--;
//}
}
int main()
{
cout << "Ryan Cloud\nThis is The Written number project\n";
//get a number
//turn number to word form
//display word form
// ask the user to input a dollar amount
cout << "\nEnter a Dollar amount\n";
cin >> userInput;
fraction = modf(userInput, &number);
// This seperates the number and the decimal into 2 variables.
//Number gets just the number and fraction just gets the decimal point from it.
getNumber ();
getToWords ();
getDecimal ();
return 0;
}
|