Thursday, August 1, 2019

Decimal To Word Converter Using Functions in Go

Write a program that will ask the user to give a number and then the program will convert the given number into word equivalent.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com


Sample Program Output


Program Listing

/* english.go
Author   : Mr. Jake Rodriguez Pomperada, MAED-IT
Date     : July 31, 2019  Wednesday 3:11 PM
Location : Bacolod City, Negros Occidental
Website  : http://www.jakerpomperada.com
Emails   : jakerpomperada@gmail.com and jake_pomperada@tup.edu.ph
*/

package main

import (
"fmt"
"math"
)

func pow(i int, p int) int {
return int(math.Pow(1000, float64(p)))
}

func spell(n int) string {
to19 := []string{"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
",Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}

tens := []string{"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}
if n == 0 {
return ""
}
if n < 20 {
return to19[n-1]
}
if n < 100 {
return tens[n/10-2] + " " + spell(n%10)
}
if n < 1000 {
return to19[n/100-1] + " Hundred " + spell(n%100)
}

for idx, w := range []string{"Thousand", "Million", "Billion"} {
p := idx + 1
if n < pow(1000, (p+1)) {
return spell(n/pow(1000, p)) + " " + w + " " + spell(n%pow(1000, p))
}
}

return "error"
}

func main() {

var val_num int

fmt.Print("\n")
fmt.Print("\tDecimal To Word Converter Using Functions")
fmt.Print("\n\n")
fmt.Print("\tGive a Number     : ")
fmt.Scanf("%d",&val_num)

result := spell(val_num)

fmt.Print("\n")
fmt.Printf("\tThe given number is %d.",val_num)
fmt.Print("\n\n")
fmt.Print("\t===== TRANSLATION RESULT =====")
fmt.Print("\n\n")
fmt.Printf("\t%s",result)
fmt.Print("\n\n")
fmt.Print("\tEnd of Program")
fmt.Print("\n")
}









No comments:

Post a Comment