Created
March 22, 2020 17:26
-
-
Save marti1125/311e85d2e116814d5a9eb766dfd0a84b to your computer and use it in GitHub Desktop.
hack rank operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://yourbasic.org/golang/round-float-to-int/