FAQ: Variables - Challenge: Temperature (Part 1)

Yes, indeed. Making a habit of surrounding operators with white space ensures better readability for both ourselves (debugging and revising) and others. White space is free. There is no benefit in crowding our code. Blank lines may be a bit much, but space around operators is a must have.

1 Like

Thanks for the explanation not only for this topic but also other ones, It was very helpful for me.

Also a little question/info, english is my second language while I can freely communicate,read or speak, sometimes explanations for programming still feels vague for me is there any way to improve my “tech-english ?”

1 Like

Wouldn’t know, to be honest. I’m not an ESL teacher. Reading lots of technical writing with a dictionary close at hand is one possible way. Time and continued effort, including writing.

After I finished the lesson, before I moved on I wanted to erase and start from scratch and try to add some things I learned from the previous lesson without looking.
I get no errors on this but it does the math the same every time, no matter what I input as the Fahrenheit temp. I’m going to go ahead and assume it’s just really late right now and I should be sleeping.

A sleep might help :slightly_smiling_face: but it’s the sequential order that’s causing the issue here. The calculation to tempc is performed before you even initialise tempf.

1 Like

Thanks! I changed mine to this

yes what was the mistake i doing writing c instead of C

1 Like

pls help!!!

accidentally snapped both my monitors lol ignore unreal

I think you forgot to re-compile your program after making edits to your code.

In the editor, your cout statements shows "The temp is " i.e. a space after the “is”, which is correct. But in the bash terminal, the space is missing in the output. Also the temperature in Celsius doesn’t match. This suggests that after making edits to the code, you didn’t re-compile your code.

In the bash terminal, the statement is showing up as:
"The temp is31.1111degrees Celsius."
whereas for a temperature of 83.0 Fahrenheit, the output should be:
"The temp is 28.3333 degrees Celsius."

I don’t see anything wrong with your code in the editor. Do the following:

  • After making any edits, click the "Run" button to save your changes in the editor (Ignore any error message in feedback). This just saves your code in the editor. It doesn’t compile your code.

  • Then, re-compile your code in the bash terminal by typing    g++ temperature.cpp

  • Finally, execute your code in the terminal by typing    ./a.out

should we type codes as given in the solution?Do we want to keep space in the same.When I type my code programme is run but I couldn’t go next lesson still I type codes as solution.

The spacing is not the issue.
Step 3 mentions:

Output exactly this: The temp is [tempc] degrees Celsius.
Don’t forget to add a \n.

You wrote "celsius" instead of "Celsius" and you are missing the newline "\n"

// You wrote:
std::cout << "The temp is " << tempc << " degrees celsius.";

// It should be:
std::cout << "The temp is " << tempc << " degrees Celsius.\n";

Your output or return values must EXACTLY match the strings/values specified in the instructions.

Thank you very much!

1 Like

Hey it says “Did you copy the phrase correctly?” for my following code:

#include <iostream> using namespace std; int main() { double tempf = 60.0; double tempc = (tempf - 32) / 1.8; cout << "The temp is " << tempc << " degrees Celsius.\n"; }

This code runs completly fine on other online compilers exactly as the question wanted.

Perhaps Step 1 and Step 2 want the declaration and initialization to happen in two separate statements.

// You wrote:
double tempf = 60.0;
double tempc = (tempf - 32) / 1.8;

// Try changing to:
double tempf = 60.0;
double tempc; 
tempc = (tempf - 32) / 1.8;

If that doesn’t work, then consider making another change as well,

// You wrote:
using namespace std;
cout << "The temp is " << tempc << " degrees Celsius.\n";  

// Try changing to:
std::cout << "The temp is " << tempc << " degrees Celsius.\n";