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 <conio.h>
#include <string>
#include <sstream>
using namespace std;
string textnum[20]=
{" ","one","two","three","four",
"five","six","seven","eight","nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen",};
string tensnum[10]=
{" ","twenty","thirty","forty",
"fifty","sixty","seventy","eighty","ninety",};
int main()
{
string date, payee, amount;
cout << "What's the date?";
getline(cin,date,'\n');
cout << "Who is the payee?";
getline(cin,payee,'\n');
cout << "What is the amount?";
getline(cin, amount,'\n');
//payee
cout << "Pay to the Order of: " << payee << endl;
//date
cout << "Date: " << date << endl;
//dollar format
cout << "$" << amount << endl;
istringstream buffer(amount);
int int_part;
buffer>>int_part;
//words
int hundred = int_part/100;
int remainder = int_part%100;
int ten = remainder/10;
int unit = remainder%10;
//cents
double dec_part=0;
buffer>> dec_part;
dec_part*=100;
//display words
cout << textnum[hundred] << " hundred ";
if (textnum[hundred] < 100)
cout << " ";
cout << tensnum[ten] << " ";
if (tensnum[ten] > 9 && tensnum[ten] < 20)
cout << textnum[unit] << " ";
cout << textnum[unit] << " ";
cout << dec_part << " cents" << endl;
cin.get();
getch();
return 0;
}
|