Here is the C++ code to convert a number into words up to one Billion . It takes input from user for a number and displays the number in words. You all should have in mind how it works exactly. Here is the algorithm.
Steps
User side
1: User asked to enter a number (the number should be in the range of one billion)
2: Screen displays the result on screen.
Developer side
1: Declare variables that are going to be used in program .
2: Take a number as input from user
3: Pass the number to the function first.
4: This function display the corresponding word if the number is twenty or less than twenty and multiples of ten.
5: If the number is not multiple of ten or not less than twenty, then if the number is within the range of 100 pass it to the function 'twodigits()'. It will break the number in digits and send both the digits to the function 'first'. The 'first' function will return a string that will be concatenated to the string from the function 'twodigit' and the control goes back to the main function.
6: If the number is greater than one hundred and within the range of one thousand then pass it to the function 'threedigit'
7: This function will break the number into digits. First digit is passed to the function 'first()' and a string "Hundred and" will be concatenated to the returned string. And other two digits will be passed to the function 'twodigits()'. It will repeat the step number 5 and the returned string will concatenated with the above string and control goes back to the main function .
8: If the number is greater than one thousand and within the range of 10000 then pass it to the function 'fourdigit' . It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Thousand". Other three digits will be passed to the function 'threedigit' and step 7 will be repeated. The returned string will be concatenated with the above string.
9: If the number is greater than 10000 and within the range of 100000 then pass it to the function 'fivedigit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Thousand". Other three digits will be passed to the function 'threedigit' and step 7 will be repeated. The returned string will be concatenated with the above string.
10: If the number is greater than 100000 and within the range of 1000000 pass it to the function 'sixdigit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Lack". Other digits will be passed to the function 'fivedigit' and step 9 will be repeated. The returned string will be concatenated with the above string.
11: If the number is greater than 100000 and within the range of 1000000 pass it to the function 'seven digit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Lack". Other digits will be passed to the function 'fivedigit' and step 9 will be repeated. The returned string will be concatenated with the above string.
12: If the number is greater than 1000000 and within the range of 10000000 pass it to the function 'eightdigit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Crore". Other digits will be passed to the function 'sevendigits' and step 9 will be repeated. The returned string will be concatenated with the above string.
13: If the number is greater than 10000000 and within the range of 100000000 pass it to the function 'eightdigit()' and so on, do it up to ten digits .
14: Program ends here.
10: If the number is greater than 100000 and within the range of 1000000 pass it to the function 'sixdigit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Lack". Other digits will be passed to the function 'fivedigit' and step 9 will be repeated. The returned string will be concatenated with the above string.
11: If the number is greater than 100000 and within the range of 1000000 pass it to the function 'seven digit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Lack". Other digits will be passed to the function 'fivedigit' and step 9 will be repeated. The returned string will be concatenated with the above string.
12: If the number is greater than 1000000 and within the range of 10000000 pass it to the function 'eightdigit()'. It will split first digit that will be passed to the function 'first' that will return a string that will be concatenated with the string "Crore". Other digits will be passed to the function 'sevendigits' and step 9 will be repeated. The returned string will be concatenated with the above string.
13: If the number is greater than 10000000 and within the range of 100000000 pass it to the function 'eightdigit()' and so on, do it up to ten digits .
14: Program ends here.
Comments
Post a Comment