CARVIEW |
Select Language
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 31 Jul 2025 15:20:42 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Last-Modified: Tue, 04 Apr 2023 18:38:14 GMT
Content-Encoding: gzip
How I Used My C++ Programming Technique - C++ Articles




- Articles
- How I Used My C++ Programming Technique
Published by analyzoh
Jun 24, 2012 (last update: Jun 14, 2014)
How I Used My C++ Programming Technique To Convert A Numerical Amount To A Verbal Amount
Score: 2.9/5 (196 votes)





INTRODUCTION
I would like to discuss a programming technique I developed in C++ several years ago for converting a numerical amount to a verbal amount. I use this in a check book register program I made for a longtime customer in my hometown of Cleveland, Ohio USA. This technique is part of a module in a larger program that is used to compose and issue checks every week for payroll, taxes, shop materials, office supplies, utilities and more. It has proven to be very reliable over a period of years. This algorithm can also be implemented for assistance with printing legal contracts, loan documents, promissory notes and many more things where a verbal amount needs to be specified.

The full C++ program code readout for this can be viewed on my website. Next, I will explain the logic flow so it can be easily understood.
GETTING SET UP
At the beginning of the C++ source code, defined constants are declared so the rest of the code can reference them for various tasks. After clicking the “print check” button, the variables and objects are declared. Next, a simple if-then logic structure is used to test if a check book register record has been selected from the check book register screen. This is necessary because the check number from the check book register screen is needed to help create the printed check. Now initialize the variables for the check and check stub. Next, retrieve the following items from the controls on the currently displayed screen. These items include check number, vendor name, invoice description, check memorandum and paid date.
For the next step, a file stream must be opened to the binary check book register data file, “cbook.txt”. Here, a do-while loop structure is entered to collect the data for each invoice to be paid. The check number for each check book register record will be matched to the one retrieved from the current data entry screen. Each matched record will retrieve the date, expense code, invoice number, invoice total, early payment discount, and net invoice amount for each specific vendor invoice to be paid with this check. There can be no more than 10 invoices on the check stub in this particular application. With each pass through the do-while loop structure, the matched check book register record will be marked as paid and the net invoice amount will be accumulated. This total will become the numerical amount that will be converted to a verbal amount.
Upon verification that at least one matching check number was found in the do-while loop structure from above, the net invoice amount total will be specified in a character array called “totpay”. This character array will be extensively utilized in the conversion to a verbal amount momentarily. But first, a file stream must be opened to the vendor binary data file, “vendor.txt”. This will be another do-while loop structure that matches the retrieved vendor name from the currently displayed screen to what is in the data file for vendors. The vendor’s street, city, state and zip code are then retrieved upon a successful match and then formatted with some simple string operations to prepare for eventual printing on the check itself.
THE BRICK AND MORTAR
Here are some sets of character arrays that define some of the verbal components used to construct the verbal amount for the check. Each of these character array sets will be assigned a specific name for the purpose of narrating the software development algorithm that utilizes them for converting the numerical amount to a verbal amount.
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the second (2nd) and fifth (5th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP A.
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the first (1st), third (3rd) and fourth (4th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP B.
This is concatenated to the verbal description variable after the “number of thousands figure” has been detected, which is the fourth (4th) position to the left of the decimal point in the numerical amount to be converted. THIS IS THE THOUSANDS DESIGNATOR.
This is concatenated to the verbal description variable after the “number of hundreds figure” has been detected, which is the third (3rd) position to the left of the decimal point in the numerical amount to be converted. THIS IS THE HUNDREDS DESIGNATOR.
This is not concatenated to the verbal description variable, but rather it is assigned after no other descriptors have been concatenated to the above variable at the end of processing. THIS IS THE ZERO DESIGNATOR.
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the first (1st) and fourth (4th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP C.
STARTING CONSTRUCTION
The first thing to do here is initialize the 70 character character array “verbal_amount” with space characters to prepare it for being updated by the algorithm that converts the numerical amount in the character array “totpay” to the verbal counterpart. A counter variable “aa” will also be used to count how many characters are appended to the char array “verbal_amount”.
Next, check to see if the 5th digit to the left of the decimal point in the numerical character array “totpay” is greater than 0 (begin structure “a”). If true, then check to see if the 5th digit to the left of the decimal point in the numerical character array “totpay” is equal to 1 (begin structure “b”). If this is true, then use GROUP C to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
End structure “b”. Next, use GROUP A to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 5th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
Begin structure “c”. If the 5th digit to the left of the decimal point in the numerical character array “totpay” does not equal 1, then use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
End structure “c”. Next, append "THOUSAND" to the character array “verbal_amount” and end structure “a”.
Begin structure “d”. If the 5th digit to the left of the decimal point is less than 1 and the 4th digit to the left of the decimal point is greater than 0, then proceed. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
Next, append "THOUSAND" to the character array “verbal_amount” and end structure “d”.
Begin structure “e”. If the 3rd digit to the left of the decimal point is greater than 0, then proceed. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 3rd digit to the left of the decimal place in the numerical character array “totpay” as shown here:
Next, append "HUNDRED" to the character array “verbal_amount” and end structure “e”.
Now check to see if the 2nd digit to the left of the decimal point in the numerical character array “totpay” is greater than 0 (begin structure “f”). If true, then check to see if the 2nd digit to the left of the decimal point in the numerical character array “totpay” is equal to 1 (begin structure “g”). If true, then use GROUP C to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 1st digit to the left of the decimal place in the numerical character array “totpay” as shown here:
End structure “g”. Next, use GROUP A to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 2nd digit to the left of the decimal place in the numerical character array “totpay” as shown here:
End structure “f”. If the 1st digit to the left of the decimal point is greater than 0 and the 2nd digit to the left of the decimal point does not equal 1, then begin structure “h”. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 1st digit to the left of the decimal place in the numerical character array “totpay” as shown here:
End structure “h”. If nothing was translated to a verbal amount from the above code (the “aa” counter variable is equal to 0 from not being incremented in the concatenation programming from above), then assign the ZERO DESIGNATOR to the verbal amount character array “verbal_amount”. Lastly, skip a space character in the verbal amount character array “verbal_amount” and append “AND”. Skip another space character and append the two (2) characters for cents in the numerical character array “totpay” followed by “/100”.
CONCLUSION
As seen from the above narrative, application development saves a lot of time and labor. When I create software, I don’t really care about making it aesthetically pleasing to the eye as long as it is easy to use, reliable and reasonably fast. This is what business people really care about. My developer skills can be traced back to the early 1990s from designing business software. Please contact me through my software developer website if you would like to learn more about the services I offer.
I would like to discuss a programming technique I developed in C++ several years ago for converting a numerical amount to a verbal amount. I use this in a check book register program I made for a longtime customer in my hometown of Cleveland, Ohio USA. This technique is part of a module in a larger program that is used to compose and issue checks every week for payroll, taxes, shop materials, office supplies, utilities and more. It has proven to be very reliable over a period of years. This algorithm can also be implemented for assistance with printing legal contracts, loan documents, promissory notes and many more things where a verbal amount needs to be specified.

The full C++ program code readout for this can be viewed on my website. Next, I will explain the logic flow so it can be easily understood.
GETTING SET UP
At the beginning of the C++ source code, defined constants are declared so the rest of the code can reference them for various tasks. After clicking the “print check” button, the variables and objects are declared. Next, a simple if-then logic structure is used to test if a check book register record has been selected from the check book register screen. This is necessary because the check number from the check book register screen is needed to help create the printed check. Now initialize the variables for the check and check stub. Next, retrieve the following items from the controls on the currently displayed screen. These items include check number, vendor name, invoice description, check memorandum and paid date.
For the next step, a file stream must be opened to the binary check book register data file, “cbook.txt”. Here, a do-while loop structure is entered to collect the data for each invoice to be paid. The check number for each check book register record will be matched to the one retrieved from the current data entry screen. Each matched record will retrieve the date, expense code, invoice number, invoice total, early payment discount, and net invoice amount for each specific vendor invoice to be paid with this check. There can be no more than 10 invoices on the check stub in this particular application. With each pass through the do-while loop structure, the matched check book register record will be marked as paid and the net invoice amount will be accumulated. This total will become the numerical amount that will be converted to a verbal amount.
Upon verification that at least one matching check number was found in the do-while loop structure from above, the net invoice amount total will be specified in a character array called “totpay”. This character array will be extensively utilized in the conversion to a verbal amount momentarily. But first, a file stream must be opened to the vendor binary data file, “vendor.txt”. This will be another do-while loop structure that matches the retrieved vendor name from the currently displayed screen to what is in the data file for vendors. The vendor’s street, city, state and zip code are then retrieved upon a successful match and then formatted with some simple string operations to prepare for eventual printing on the check itself.
THE BRICK AND MORTAR
Here are some sets of character arrays that define some of the verbal components used to construct the verbal amount for the check. Each of these character array sets will be assigned a specific name for the purpose of narrating the software development algorithm that utilizes them for converting the numerical amount to a verbal amount.
|
|
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the second (2nd) and fifth (5th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP A.
|
|
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the first (1st), third (3rd) and fourth (4th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP B.
|
|
This is concatenated to the verbal description variable after the “number of thousands figure” has been detected, which is the fourth (4th) position to the left of the decimal point in the numerical amount to be converted. THIS IS THE THOUSANDS DESIGNATOR.
|
|
This is concatenated to the verbal description variable after the “number of hundreds figure” has been detected, which is the third (3rd) position to the left of the decimal point in the numerical amount to be converted. THIS IS THE HUNDREDS DESIGNATOR.
|
|
This is not concatenated to the verbal description variable, but rather it is assigned after no other descriptors have been concatenated to the above variable at the end of processing. THIS IS THE ZERO DESIGNATOR.
|
|
The above character array contents are selectively concatenated to the verbal description variable depending on what numbers are in the first (1st) and fourth (4th) positions to the left of the decimal point in the numerical amount to be converted. THIS IS GROUP C.
STARTING CONSTRUCTION
The first thing to do here is initialize the 70 character character array “verbal_amount” with space characters to prepare it for being updated by the algorithm that converts the numerical amount in the character array “totpay” to the verbal counterpart. A counter variable “aa” will also be used to count how many characters are appended to the char array “verbal_amount”.
Next, check to see if the 5th digit to the left of the decimal point in the numerical character array “totpay” is greater than 0 (begin structure “a”). If true, then check to see if the 5th digit to the left of the decimal point in the numerical character array “totpay” is equal to 1 (begin structure “b”). If this is true, then use GROUP C to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
End structure “b”. Next, use GROUP A to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 5th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
Begin structure “c”. If the 5th digit to the left of the decimal point in the numerical character array “totpay” does not equal 1, then use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
End structure “c”. Next, append "THOUSAND" to the character array “verbal_amount” and end structure “a”.
Begin structure “d”. If the 5th digit to the left of the decimal point is less than 1 and the 4th digit to the left of the decimal point is greater than 0, then proceed. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 4th digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
Next, append "THOUSAND" to the character array “verbal_amount” and end structure “d”.
Begin structure “e”. If the 3rd digit to the left of the decimal point is greater than 0, then proceed. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 3rd digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
Next, append "HUNDRED" to the character array “verbal_amount” and end structure “e”.
Now check to see if the 2nd digit to the left of the decimal point in the numerical character array “totpay” is greater than 0 (begin structure “f”). If true, then check to see if the 2nd digit to the left of the decimal point in the numerical character array “totpay” is equal to 1 (begin structure “g”). If true, then use GROUP C to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 1st digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
End structure “g”. Next, use GROUP A to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 2nd digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
End structure “f”. If the 1st digit to the left of the decimal point is greater than 0 and the 2nd digit to the left of the decimal point does not equal 1, then begin structure “h”. Use GROUP B to assign a descriptor to the verbal amount character array “verbal_amount” based on the number that is contained in the 1st digit to the left of the decimal place in the numerical character array “totpay” as shown here:
|
|
End structure “h”. If nothing was translated to a verbal amount from the above code (the “aa” counter variable is equal to 0 from not being incremented in the concatenation programming from above), then assign the ZERO DESIGNATOR to the verbal amount character array “verbal_amount”. Lastly, skip a space character in the verbal amount character array “verbal_amount” and append “AND”. Skip another space character and append the two (2) characters for cents in the numerical character array “totpay” followed by “/100”.
CONCLUSION
As seen from the above narrative, application development saves a lot of time and labor. When I create software, I don’t really care about making it aesthetically pleasing to the eye as long as it is easy to use, reliable and reasonably fast. This is what business people really care about. My developer skills can be traced back to the early 1990s from designing business software. Please contact me through my software developer website if you would like to learn more about the services I offer.
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us