Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created March 22, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marti1125/311e85d2e116814d5a9eb766dfd0a84b to your computer and use it in GitHub Desktop.
Save marti1125/311e85d2e116814d5a9eb766dfd0a84b to your computer and use it in GitHub Desktop.
hack rank operators
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
"math"
)
// Complete the solve function below.
func solve(meal_cost float64, tip_percent int32, tax_percent int32) {
tip := meal_cost * (float64(tip_percent) / 100)
tax := meal_cost * (float64(tax_percent) / 100)
//fmt.Println(tip)
//fmt.Println(float64(tax_percent) / 100)
fmt.Println(math.Round(meal_cost + tip + tax))
}
func main() {
reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
meal_cost, err := strconv.ParseFloat(readLine(reader), 64)
checkError(err)
tip_percentTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
checkError(err)
tip_percent := int32(tip_percentTemp)
tax_percentTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
checkError(err)
tax_percent := int32(tax_percentTemp)
solve(meal_cost, tip_percent, tax_percent)
}
func readLine(reader *bufio.Reader) string {
str, _, err := reader.ReadLine()
if err == io.EOF {
return ""
}
return strings.TrimRight(string(str), "\r\n")
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
@marti1125
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment