-
Notifications
You must be signed in to change notification settings - Fork 0
/
100001846.go
47 lines (36 loc) · 901 Bytes
/
100001846.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
)
func calculateTip(tagihan float64) (float64, float64) {
var tipRate float64
if tagihan >= 50 && tagihan <= 300 {
tipRate = 0.15
} else {
tipRate = 0.20
}
tip := tagihan * tipRate
total := tagihan + tip
return tip, total
}
func main() {
var tagihan float64
fmt.Print("Masukkan nilai tagihan: ")
fmt.Scan(&tagihan)
tip, total := calculateTip(tagihan)
outputText := fmt.Sprintf("Tagihannya: Rp. %.2f\nTipnya: Rp. %.2f\nTotal nilainya: Rp. %.2f\n", tagihan, tip, total)
// Membuka file output.txt untuk penulisan
file, err := os.Create("output.txt")
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
// Menulis output ke file
_, err = file.WriteString(outputText)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Output telah ditulis ke output.txt")