Skip to content

Commit

Permalink
Session 5
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed committed Jun 30, 2022
1 parent d80d9f6 commit 4430901
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 05-ConditionalStatements/01-IfElse/ifelse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import "fmt"

func main() {

var salary float64
var minSalary float64 = 5_600_000
var taxPercent float64 = 0
var knowledgeBase bool = true

fmt.Print("Enter your salary: ")
fmt.Scanln(&salary)

if salary <= minSalary {
taxPercent = 0
} else if knowledgeBase || salary > minSalary && salary <= minSalary*2 {
taxPercent = 0.05
} else if salary > minSalary*2 && salary <= minSalary*3 {
taxPercent = 0.07
} else if salary > minSalary*3 && salary <= minSalary*4 {
taxPercent = 0.10
} else {
taxPercent = 0.15
}

fmt.Printf("Your tax percent is: %.2f\n", taxPercent)
fmt.Printf("Your tax is: %.2f\n", taxPercent*salary)

fmt.Printf("Your salary is: %.2f\n", salary-taxPercent*salary)

}
23 changes: 23 additions & 0 deletions 05-ConditionalStatements/02-Switch/switch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import "fmt"

func main() {
var score float64

println("Enter your score: ")
fmt.Scanln(&score)

switch {
case score >= 16 && score <= 20:
println("A")
case score >= 11 && score <= 15.99:
println("B")
case score >= 6 && score <= 10.99:
println("C")
case score >= 0 && score <= 5.99:
println("D")
default:
println("Unknown")
}
}
28 changes: 28 additions & 0 deletions 05-ConditionalStatements/02-Switch/switch2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import "fmt"

func main() {

var num int
var provinceName string

println("Please enter num: ")

fmt.Scanln(&num)

switch num {
case 72, 82, 92:
provinceName = "Mazandaran"
case 11, 22, 33, 44, 55, 66, 77, 88, 99, 10, 20, 30, 40, 50, 60, 70, 80, 90:
provinceName = "Tehran"
case 13, 23, 43, 53:
provinceName = "Isfahan"
case 47, 57, 67:
provinceName = "Markazi"
default:
provinceName = "Unknown"
}

println(provinceName)
}
32 changes: 32 additions & 0 deletions 05-ConditionalStatements/02-Switch/switch3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import "fmt"

func main() {

var salary float64
var minSalary float64 = 5_600_000
var taxPercent float64 = 0

fmt.Print("Enter your salary: ")
fmt.Scanln(&salary)

switch {
case salary <= minSalary:
taxPercent = 0
case salary > minSalary && salary <= minSalary*2:
taxPercent = 0.05
case salary > minSalary*2 && salary <= minSalary*3:
taxPercent = 0.07
case salary > minSalary*3 && salary <= minSalary*4:
taxPercent = 0.10
default:
taxPercent = 0.15
}

fmt.Printf("Your tax percent is: %.2f\n", taxPercent)
fmt.Printf("Your tax is: %.2f\n", taxPercent*salary)

fmt.Printf("Your salary is: %.2f\n", salary-taxPercent*salary)

}
26 changes: 26 additions & 0 deletions 05-ConditionalStatements/03-Switch/break.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
)

func main() {
var score float64

println("Enter your score: ")
fmt.Scanln(&score)

switch {
case score >= 16 && score <= 20:
println("A")
break
case score >= 11 && score <= 15.99:
println("B")
case score >= 6 && score <= 10.99:
println("C")
case score >= 0 && score <= 5.99:
println("D")
default:
println("Unknown")
}
}
29 changes: 29 additions & 0 deletions 05-ConditionalStatements/03-Switch/fallThrough-bad.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"strings"
)

func main() {

var notificationType string // "sms,email,push"

println("Enter notification type: ")

fmt.Scanln(&notificationType)

switch {
case strings.Contains(notificationType, "sms"):
println("SMS sent")
fallthrough
case strings.Contains(notificationType, "email"):
println("Email sent")
fallthrough
case strings.Contains(notificationType, "push"):
println("Push sent")
default:
println("Unknown")
}

}
58 changes: 58 additions & 0 deletions 05-ConditionalStatements/03-Switch/fallThrough-good.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import "fmt"

const monthDays1 int = 31
const monthDays2 int = 30
const monthDays3 int = 29

func main() {

var month int
var totalDays int = 0

println("Please enter a month number: ")

fmt.Scanln(&month)

switch month {
case 12:
totalDays += monthDays3
fallthrough
case 11:
totalDays += monthDays2
fallthrough
case 10:
totalDays += monthDays2
fallthrough
case 9:
totalDays += monthDays2
fallthrough
case 8:
totalDays += monthDays2
fallthrough
case 7:
totalDays += monthDays2
fallthrough
case 6:
totalDays += monthDays1
fallthrough
case 5:
totalDays += monthDays1
fallthrough
case 4:
totalDays += monthDays1
fallthrough
case 3:
totalDays += monthDays1
fallthrough
case 2:
totalDays += monthDays1
fallthrough
case 1:
totalDays += monthDays1

}

println("Total days: ", totalDays)
}

0 comments on commit 4430901

Please sign in to comment.