How To Only Output The Decimal Numbers?
Dec 1, 2015 at 2:27am UTC
I'm writing a program that when any number between 0 and 1 Billion is input, that number is output in words, *Except* the decimals are output as numbers. It's supposed to be like if you wrote a check. I'm having trouble isolating the decimals, so that when a xxxx.yy is input, I can take yy and output it. Thoughts?
This is by no means perfect, nor is it the most efficient way to do this, but this is what I came up with.
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
//CheckChanger
#include <iostream>
#include <math.h>
using namespace std;
void DoOneDigit(int num)
{
switch (num)
{
case 1: cout << "One " ;
break ;
case 2: cout << "Two " ;
break ;
case 3: cout << "Three " ;
break ;
case 4: cout << "Four " ;
break ;
case 5: cout << "Five " ;
break ;
case 6: cout << "Six " ;
break ;
case 7: cout << "Seven " ;
break ;
case 8: cout << "Eight " ;
break ;
case 9: cout << "Nine " ;
break ;
case 10: cout << "Ten " ;
break ;
}
}
void DoTeenDigits(int num)
{
switch (num)
{
case 11: cout << "Eleven " ;
break ;
case 12: cout << "Twelve " ;
break ;
case 13: cout << "Thirteen " ;
break ;
case 14: cout << "Forteen " ;
break ;
case 15: cout << "Fifteen " ;
break ;
case 16: cout << "Sixteen " ;
break ;
case 17: cout << "Seventeen " ;
break ;
case 18: cout << "Eighteen " ;
break ;
case 19: cout << "Nineteen " ;
break ;
}
}
void DoTwoDigits(int num)
{
int tenderOne, tenderTwo;
tenderTwo = num / 10;
tenderOne = num % 10;
switch (tenderTwo)
{
case 1: cout << "Ten " ;
break ;
case 2: cout << "Twenty " ;
break ;
case 3: cout << "Thirty " ;
break ;
case 4: cout << "Forty " ;
break ;
case 5: cout << "Fifty " ;
break ;
case 6: cout << "Sixty " ;
break ;
case 7: cout << "Seventy " ;
break ;
case 8: cout << "Eighty " ;
break ;
case 9: cout << "Ninety " ;
break ;
}
DoOneDigit(tenderOne);
}
void DoThreeDigits(int num)
{
int tenderTwo, tenderThree;
tenderThree = num / 100;
tenderTwo = num % 100;
DoOneDigit(tenderThree);
cout << "Hundred " ;
if (!(tenderTwo >= 11 && tenderTwo <= 19))
DoTwoDigits(tenderTwo);
else
DoTeenDigits(tenderTwo);
}
void DoFourDigits(int num)
{
int tenderThree, tenderFour;
tenderFour = num / 1000;
tenderThree = num % 1000;
DoOneDigit(tenderFour);
cout << "Thousand " ;
if (!(tenderThree >= 11 && tenderThree <= 19))
DoThreeDigits(tenderThree);
else
DoTeenDigits(tenderThree);
}
void DoFiveDigits(int num)
{
int tenderFour, tenderFive;
tenderFive = num / 1000;
tenderFour = num % 1000;
if (!(tenderFive >= 11 && tenderFive <= 19))
DoTwoDigits(tenderFive);
else
DoTeenDigits(tenderFive);
DoFourDigits(tenderFour);
}
void DoSixDigits(int num)
{
int tenderFive, tenderSix;
tenderSix = num / 1000;
tenderFive = num % 1000;
DoThreeDigits(tenderSix);
cout << "Thousand " ;
if (!(tenderFive >= 11 && tenderFive <= 19))
DoThreeDigits(tenderFive);
else
DoTeenDigits(tenderFive);
}
void DoSevenDigits(int num)
{
int tenderSix, tenderSeven;
tenderSeven = num / 1000000;
tenderSix = num % 1000000;
DoOneDigit(tenderSeven);
cout << "Million " ;
DoSixDigits(tenderSix);
}
void DoEightDigits(int num)
{
int tenderSeven, tenderEight;
tenderEight = num / 1000000;
tenderSeven = num % 1000000;
if (!(tenderEight >= 11 && tenderEight <= 19))
DoTwoDigits(tenderEight);
else
DoTeenDigits(tenderEight);
DoSevenDigits(tenderSeven);
}
void DoNineDigits(int num)
{
int tenderEight, tenderNine;
tenderNine = num / 1000000;
tenderEight = num % 1000000;
DoThreeDigits(tenderNine);
DoEightDigits(tenderEight);
}
int main()
{
int wayOut = 1;
while (wayOut != 0)
{
int amt, cents;
//, dec, fullDec;
cout << "Amount? " ;
cin >> amt;
if (amt == 0)
{
wayOut = 0;
}
if (amt == 1)
{
cout << "One Dollar and " << cents << " Cents" << endl;
}
if (amt >=2 && amt <=999999999)
{
if (amt >= 2 && amt <= 10)
{
DoOneDigit(amt);
}
if (amt >= 11 && amt <= 19)
{
DoTeenDigits(amt);
}
if (amt >= 20 && amt <= 99)
{
DoTwoDigits(amt);
}
if ( amt >= 100 && amt <= 999)
{
DoThreeDigits(amt);
}
if (amt >= 1000 && amt <= 9999)
{
DoFourDigits(amt);
}
if (amt >= 10000 && amt <= 99999)
{
DoFiveDigits(amt);
}
if (amt >= 100000 && amt <= 999999)
{
DoSixDigits(amt);
}
if (amt >= 1000000 && amt <= 9999999)
{
DoSevenDigits(amt);
}
if (amt >= 10000000 && amt <= 99999999)
{
DoEightDigits(amt);
}
if (amt >= 100000000 && amt <= 999999999)
{
DoNineDigits(amt);
}
cout << "Dollars and " << cents << " Cents" << endl;
}
if (amt == 1000000000)
{
cents = 0;
cout << "One Billion Dollars and No Cents" << endl;
}
}
}
Dec 1, 2015 at 3:24am UTC
Last edited on Dec 1, 2015 at 3:24am UTC
Topic archived. No new replies allowed.