Ask coding questions

← Back to all posts
Smart Thermostat exercise
Tmeadows97

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.

// My code, as is, works but it makes the constant labels seem strange. Specifically, the isOn constant. I'm also getting an error like other people where it doesn't match my teachers answer which is:
( false| true )


Any advice is much appreciated. Thank you! This is Swift btw.

Voters
Tmeadows97
Comments
hotnewtop
LawsonLarge

A smart thermostat is a part of the modern lifestyle that helps you control your home and relax in the evenings. If you struggle to find the right place to put your thermostat - perhaps it's too far from your bed or too close to the kitchen window - consider moving it. There is no doubt that a heated place is much better for us than one that's covered in frost. If making the necessary adjustments to your house isn't a chore, then nothing else in life will be. When I bought it, I asked the guys from https://www.waychoffsac.com to help me with the installation. They guys did a great job.

CodeLongAndPros

To fix the error where output is different, you can just change you output:

Tmeadows97

@CodeLongAndPros

This is the error I get.

CodeLongAndPros

@Tmeadows97 I can't help if the test case is strange. That should be a question for your teacher

Tmeadows97

@CodeLongAndPros
Ok thanks for your help though.

CodeLongAndPros

@Tmeadows97 I like to think that I did pretty good without knowing a single thing about swift :D.

However, can you try printing boolean values?
I think the test cases is false OR true.

Tmeadows97

@CodeLongAndPros
I thought it could be OR too but I have never seen it print like that.
false| true

I thought it would be like " false || true ". "||" this is the OR swift operator.

CodeLongAndPros

@Tmeadows97 Ah. I was reading it as a regex.

Tmeadows97

@CodeLongAndPros

I think you were right about the test case being wrong.
I printed exactly what it said it was missing and it passed me even though I'm positive that " false| true " makes no sense.

CodeLongAndPros

// My code, as is, works but it makes the constant labels seem strange. Specifically, the isOn constant.

What do you mean?

Tmeadows97

@CodeLongAndPros

I have tried the 4 combinations that I could with temperature being above or below 68 or it is raining or it is not raining and what is printed is correct how it should.

When I read the code line:

if isOn {
print("The air conditioner is off.")
}

It sounds opposite to say "If it is on, print it is off"

CodeLongAndPros

@Tmeadows97
I don't really know swift, but using C-style syntax: (The ! means not)
You could then say:

CodeLongAndPros

Also, what language is this in?

Tmeadows97

@CodeLongAndPros
sorry I'm new, this is my first post. It's Swift btw.

CodingCactus

@Tmeadows97 is this what you mean:

https://repl.it/@CodingCactus/Thermostat

If it is, please select as answer (tick next to coment)

CodingCactus

@Tmeadows97, if it is just the outputs on your current code which don't give out what is wanted by the teacher (true|false), then you can just change them to:

CodeLongAndPros

Can you put your code between ``` and ```?
Help us help you.

Tmeadows97

@CodeLongAndPros
Yes, thank you!

CodeLongAndPros

@Tmeadows97 Sorry, it's the backtick. "`" It's above the tab key on my keyboard.

Tmeadows97

@CodeLongAndPros
Ok I think I got it now. Same for me too.