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 <iomanip>
#include <time.h>
#include <sstream>
#include <string>
using namespace std;
void LoadCharAmt();
void dollarFormat(string &);
string CharAmt[30], fname, lname, fullname;
char another;
int main ()
{
do{
fname.clear();
lname.clear();
fullname.clear();
double amt=0, amt1;
int ttc=0, tc=0, hc=0, tenc=1, int_amt=0, length=0;
struct tm* ptrTime;
time_t t=time(0);
ptrTime=localtime(&t);
system("CLS");
cout << " * * * * CHECK WRITER * * * * ";
cout <<endl << " Enter First Name: ";
getline (cin, fname);
cout <<endl << " Enter Last Name: ";
getline (cin, lname);
cout << endl << "Enter the Amount of the Check:";
cout << endl << "(up to 99,999.99): ";
cin >>amt;
amt1=amt;
//Add fname and lname
fullname = fname + " " + lname;
//Get String Length
length=strlen(fullname.c_str());
//Convert Double to String
string s;
stringstream ss, ss2;
ss << amt1;
ss>>s;
//Comma (Couldn't get dollarFormat to work???)
for ( short i = s.length() - 3; i > 0; i -= 3 )
{
s.insert(i, ",");
}
//Break Up
if (amt >= 20000)
while (amt > 10000)
{
ttc++;
amt-=10000;
}
if (amt >= 1000)
while (amt >=1000)
{
tc++;
amt-=1000;
}
if (amt >= 100)
while (amt >= 100)
{
hc++;
amt-=100;
}
if (amt >=20)
while (amt >=10)
{
tenc++;
amt-=10;
}
LoadCharAmt();
//Output
cout << endl << endl;
cout << setw(55) << "Date: ";
cout<<ptrTime->tm_mon+1<< "/"<<ptrTime->tm_mday<<"/";
cout<<ptrTime->tm_year+1900;
cout << endl << " PAY TO THE";
cout << endl << " ORDER OF: " << fullname << setw(39-length) <<"$"<< s;
cout << endl << "______________________________________________________________";
cout << endl;
// Ten Thousands
if (ttc>0)
cout << CharAmt[20+ttc];
//Thousands
if (tc>0)
cout << " " << CharAmt[tc] << " Thousand";
else (cout << " Thousand");
//Hundreds
if (hc>0)
cout << " " << CharAmt[hc] << " Hundred";
//Ten
if (tenc>1)
cout << " " << CharAmt[19+tenc];
//Everything Else
int_amt = static_cast<int>(amt);
cout << " " << CharAmt[int_amt];
cout << endl;
cout << endl << "______________________________________________________________";
cout << endl;
cout << " Do another? (Y or N): ";
cin>>another;
}while(another != 'N' && another !='n');
system("Pause");
return 0;
}
// Functions
void LoadCharAmt()
{
CharAmt[1]="One";
CharAmt[2]="Two";
CharAmt[3]="Three";
CharAmt[4]="Four";
CharAmt[5]="Five";
CharAmt[6]="Six";
CharAmt[7]="Seven";
CharAmt[8]="Eight";
CharAmt[9]="Nine";
CharAmt[10]="Ten";
CharAmt[11]="Eleven";
CharAmt[12]="Twelve";
CharAmt[13]="Thirteen";
CharAmt[14]="Fourteen";
CharAmt[15]="Fifteen";
CharAmt[16]="Sixteen";
CharAmt[17]="Seventeen";
CharAmt[18]="Eighteen";
CharAmt[19]="Nineteen";
CharAmt[20]="Twenty";
CharAmt[21]="Ten";
CharAmt[22]="Twenty";
CharAmt[23]="Thirty";
CharAmt[24]="Forty";
CharAmt[25]="Fifty";
CharAmt[26]="Sixty";
CharAmt[27]="Seventy";
CharAmt[28]="Eighty";
CharAmt[29]="Ninety";
}
void dollarFormat (string ¤cy)
{
int dp;
dp=currency.find('.');
if (dp>3)
{
for (int x = dp-3; x>0; x-=3)
currency.insert(x, ",");
}
currency.insert(0,"$");
}
|