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
|
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string textnum[10]=
{" ","one","two","three","four",
"five","six","seven","eight","nine"};
string tensnum[10]=
{" ","ten","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 ";
cout << tensnum[ten] << " ";
cout << textnum[unit] << " ";
cout << dec_part << " cents" << endl;
cin.get();
return 0;
}
|