-1

I would like to print the result of the bool value When I do it I have "true" instead the amount. I know it probably sounds really stupid but I'm just getting started with swift

var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
let months5weeks:Bool = true
let months4weeks:Bool = true

if months5weeks {

normalpay = hoursWageHours * months5WeeksHours

if months4weeks {

    normalpay = hoursWageHours * months4WeeksHours
}
}

or woud that make more sence even if didnt print the result still

var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0


if monthsWeek == 195 {

normalpay = hoursWageHours * months5WeeksHours

if monthsWeek == 4 {

    normalpay = hoursWageHours * months4WeeksHours
}

}

monthsWeek = 4

Kevin
  • 1,076
  • 4
  • 22
  • 49

2 Answers2

4

I came here looking for an actual print of a bool. It turns out you can do this:

var a_bool = false
print("a_bool is ")
println(a_bool)

And you can do this with ints:

var a_int = 42
println("This is an int " + String(a_int))

You can't do this with bools though. However you can do:

println("This is a bool " + String(stringInterpolationSegment: a_bool))

This is the closet I can come up with for something like this:

println("a_bool is ", a_bool) // does not work 
println("a_bool is " + a_bool) // also does not work

Later on, I learned you can use \(variable) embedding like this:

println("This is an int \(a_int)")

netskink
  • 4,033
  • 2
  • 34
  • 46
  • While the OP's question is fairly bad this answer is the one I was after when I reached this question so thanks for spending the time to answer the question the OP's title indicates they wanted to know the answer to! :) – GazB Dec 22 '19 at 11:08
3

A boolean variable can take only 2 values (true or false). So it is logical that when you print it you have true or false.

LastMove
  • 2,482
  • 1
  • 15
  • 25