Ask coding questions

← Back to all posts
Swift thermostat program
r0b1nhoods (0)

Okay im new to swift coding and and trying to figure this out but cant seem to write it correctly. how would i write this in swift???

Write a program for your smart thermostat. Do the following using a temperature, isRaining, and isOn property,

If the temperature is less than 68 degrees or it is raining, the Air Conditioning should be turned off. Otherwise the Air Conditioning should be turned on.

Try different combinations of temperatures and weather conditions (raining vs not raining) to make sure your thermostat works correctly.

Use a print statement to check the air conditioning's status.

jeremyjameslv (2)

i did this also the program worked but it says my teacher was looking for a true| false answer

ash15khng (650)

Do something like

if temperature < 68 || isRaining { 
    print("Air conditioning off")
} else {
    print("Air conditioning on")

This uses a if-else statement.

r0b1nhoods (0)

tried that but its giving error code "use of unresolved identifier" for the isRaining

ash15khng (650)

@r0b1nhoods Did you define isRaining?