messing_around/messing_around.go

35 lines
778 B
Go

package main
import "fmt"
func main() {
originalPrice := 0.0
discount := 0.0
fmt.Printf("Enter the price of the item: ")
_, err := fmt.Scanf("%f", &originalPrice)
if err != nil {
fmt.Printf("Invalid price: %s\n", err)
return
}
fmt.Printf("Enter the percentage off: ")
_, err = fmt.Scanf("%f", &discount)
if err != nil {
fmt.Printf("Invalid discount: %s\n", err)
return
}
salePrice, percentOff := getSalePrice(originalPrice, discount)
fmt.Printf("The percent off is %.2f.\nThe Price will be: %.2f\n", percentOff, salePrice)
}
func getSalePrice(originalPrice, discount float64) (float64, float64) {
percentOff := discount / 100.0
adjustedPrice := originalPrice * percentOff
salePrice := originalPrice - adjustedPrice
return salePrice, percentOff
}