Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- //Function name: dig1
- //Purpose: Prints the english version of the last digit of the original number
- //Parameters: The last digit of the original number
- //Return value: None
- void dig1(int a)
- {
- if (a == 0) {
- cout << endl;
- }
- else if (a == 1) {
- cout << "ONE" << endl;
- }
- else if (a == 2) {
- cout << "TWO" << endl;
- }
- else if (a == 3) {
- cout << "THREE" << endl;
- }
- else if (a == 4) {
- cout << "FOUR" << endl;
- }
- else if (a == 5) {
- cout << "FIVE" << endl;
- }
- else if (a == 6) {
- cout << "SIX" << endl;
- }
- else if (a == 7) {
- cout << "SEVEN" << endl;
- }
- else if (a == 8) {
- cout << "EIGHT" << endl;
- }
- else if (a == 9) {
- cout << "NINE" << endl;
- }
- }
- //Function name: dig2
- /*Purpose: Prints the english version of the 3rd digit of the original number. If the 3rd digit is 1, prints the word associated with 1 and the last
- digit. Also sends the value of the last digit to dig1.*/
- //Parameters: The last two digits of the original number
- //Return value: None
- void dig2(int c)
- {
- int a = c / 10;
- int b = c % 10;
- if (a == 0) {
- dig1(b);
- }
- else if (a == 1) {
- if (b == 0) {
- cout << "TEN" << endl;
- }
- else if (b == 1) {
- cout << "ELEVEN" << endl;
- }
- else if (b == 2) {
- cout << "TWELVE" << endl;
- }
- else if (b == 3) {
- cout << "THIRTEEN" << endl;
- }
- else if (b == 4) {
- cout << "FOURTEEN" << endl;
- }
- else if (b == 5) {
- cout << "FIFTEEN" << endl;
- }
- else if (b == 6) {
- cout << "SIXTEEN" << endl;
- }
- else if (b == 7) {
- cout << "SEVENTEEN" << endl;
- }
- else if (b == 8) {
- cout << "EIGHTEEN" << endl;
- }
- else if (b == 9) {
- cout << "NINETEEN" << endl;
- }
- }
- else if (a == 2) {
- cout << "TWENTY ";
- dig1(b);
- }
- else if (a == 3) {
- cout << "THIRTY ";
- dig1(b);
- }
- else if (a == 4) {
- cout << "FOURTY ";
- dig1(b);
- }
- else if (a == 5) {
- cout << "FIFTY ";
- dig1(b);
- }
- else if (a == 6) {
- cout << "SIXTY ";
- dig1(b);
- }
- else if (a == 7) {
- cout << "SEVENTY ";
- dig1(b);
- }
- else if (a == 8) {
- cout << "EIGHTY ";
- dig1(b);
- }
- else if (a == 9) {
- cout << "NINETY ";
- dig1(b);
- }
- }
- //Function name: dig3
- //Purpose: Prints the english version of the 2nd digit of the original number. Also sends the value of the last 2 digits to dig2.
- //Parameters: The last three digits of the original number
- //Return value: None
- void dig3(int c)
- {
- int a = c / 100;
- int b = c % 100;
- if (a == 0) {
- dig2(b);
- }
- else if (a == 1) {
- cout << "ONE HUNDRED ";
- dig2(b);
- }
- else if (a == 2) {
- cout << "TWO HUNDRED ";
- dig2(b);
- }
- else if (a == 3) {
- cout << "THREE HUNDRED ";
- dig2(b);
- }
- else if (a == 4) {
- cout << "FOUR HUNDRED ";
- dig2(b);
- }
- else if (a == 5) {
- cout << "FIVE HUNDRED ";
- dig2(b);
- }
- else if (a == 6) {
- cout << "SIX HUNDRED ";
- dig2(b);
- }
- else if (a == 7) {
- cout << "SEVEN HUNDRED ";
- dig2(b);
- }
- else if (a == 8) {
- cout << "EIGHT HUNDRED ";
- dig2(b);
- }
- else if (a == 9) {
- cout << "NINE HUNDRED ";
- dig2(b);
- }
- }
- //Function name: dig4
- //Purpose: Prints the english version of the 1st digit of the original number. Also sends the value of the last 3 digits to dig3.
- //Parameters: The original number
- //Return value: None
- void dig4(int c)
- {
- int a = c / 1000;
- int b = c % 1000;
- if (a == 0) {
- dig3(b);
- }
- else if (a == 1) {
- cout << "ONE THOUSAND ";
- dig3(b);
- }
- else if (a == 2) {
- cout << "TWO THOUSAND ";
- dig3(b);
- }
- else if (a == 3) {
- cout << "THREE THOUSAND ";
- dig3(b);
- }
- else if (a == 4) {
- cout << "FOUR THOUSAND ";
- dig3(b);
- }
- else if (a == 5) {
- cout << "FIVE THOUSAND ";
- dig3(b);
- }
- else if (a == 6) {
- cout << "SIX THOUSAND ";
- dig3(b);
- }
- else if (a == 7) {
- cout << "SEVEN THOUSAND ";
- dig3(b);
- }
- else if (a == 8) {
- cout << "EIGHT THOUSAND ";
- dig3(b);
- }
- else if (a == 9) {
- cout << "NINE THOUSAND ";
- dig3(b);
- }
- }
- int main()
- {
- int number;
- int c = 0;
- while (c < 1) {
- cout << "Enter a number between 0 and 9999." << endl;
- cin >> number;
- if (number >= 0 && number <= 9999) {
- if (number == 0) {
- cout << "ZERO" << endl;
- break;
- }
- else if (number > 0 && number < 10) {
- dig1(number);
- break;
- }
- else if (number >= 10 && number < 100) {
- dig2(number);
- break;
- }
- else if (number >= 100 && number < 1000) {
- dig3(number);
- break;
- }
- else if (number >= 1000 && number < 10000) {
- dig4(number);
- break;
- }
- }
- else {
- cout << "You did not enter a number between 0 and 9999." << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment