From fa67559df6b79acf2e6b938c4a5506a2b8d890da Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 8 May 2020 12:35:14 -0400 Subject: [PATCH] initial commit --- .gitignore | 120 ++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 ++ messing_around.go | 34 +++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 messing_around.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6cc5b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,120 @@ + +# Created by https://www.gitignore.io/api/vim,linux,macos,windows,go +# Edit at https://www.gitignore.io/?templates=vim,linux,macos,windows,go + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/vim,linux,macos,windows,go +messing_around diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cf198e4 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module code.chrissexton.org/cws/messing_around + +go 1.14 diff --git a/messing_around.go b/messing_around.go new file mode 100644 index 0000000..cb9abc8 --- /dev/null +++ b/messing_around.go @@ -0,0 +1,34 @@ +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 +}