FAQ: Variables - Challenge: Temperature (Part 1)

This community-built FAQ covers the “Challenge: Temperature (Part 1)” exercise from the lesson “Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C++

FAQs on the exercise Challenge: Temperature (Part 1)

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

8 posts were split to a new topic: [FIXED] C++ lesson specifics and compiling issues

I am currently working on step 3 (Display the result). The code looks right to me, but I can’t get past this step. Everytime I try to run the code, I get an error that says: “Did output the exact same phrase?”

Here is the code that I have so far:

#include

int main() {

double tempf = 37.0;
double tempc;

tempc = (tempf - 32) / 1.8;

std::cout << “The temp is " << tempc << " degrees Celcius.\n”;

}

I even looked at the hints to figure this out, but I can’t see what’s wrong.

1 Like

Should that be,

#include <iostream>

?

1 Like

I am not sure why it isn’t showing in the window, but I do have that line "#include <iostream> "

#include

int main() {

double tempf = 83.0;
double tempc;
tempc = (tempf - 32) / 1.8;

std::cout<<“The temp is " <<tempc<<” degrees Celsius.\n";

}

Its Celsius not Celcius and in line " degrees…" first place is blank-with space.
First line include is not appear all because of brackets…(at this forum answers)

So I got my code looking just like your example (even correction the spelling of Celsius), but it did not work initially. To get it to work, I had to completely erase everything and retype it, and then it actually worked! Thanks for your help!

Thanks for responding and looking to adapt the tutorial! I come from a less formal scripting background so forgive me if my terminology isn’t exact. This was the only tutorial so far that was a bit confusing. I’d clarify “double” as a the type of variable and the “tempf” and “tempc” as the names of of the variable in the instruction text. And remind the student that there doesn’t need to be a “= value” after the name (I forgot and that’s what confused me).

I ended up doing something like:

double tempf =41
double tempc = C

C = (tempf-32)/1.8;

Once I saw the solution it made sense, but since it was the first time I’d seen “double” and forgot about the not needing “= value” in this context, I fumbled a bit.

So far the tutorials have been great for this new coder! Thanks for all the hard work!

1 Like

I am getting an error when I try to compile. Here’s my code:

#include

int main() {

double tempf;
double tempc;

// Ask the user

std::cout << "Enter the temperature in Fahrenheit: ";
std::cin >> tempf;

tempc = (tempf - 32) / 1.8;

}

I can’t cut and paste the error message, but it’s pretty long winded and trails off the screen.

??

Hi there, thanks for putting this course up on Codecademy for free!
while doing this lesson, im noticing that my results shows up twice in my final message on the console. Here’s my code:

double tempf = 0;
double tempc = 0;

std::cout << “Enter the temperature in Fahrenheit \n”;
std::cin >> tempf;

std::cout << (tempc = (tempf-32)/ 1.8);

std::cout << “The temp is " << tempc << " degrees Celsius.\n”;

return 0;

After I have the user enter a temperature (54°) for Fahrenheit, i’ll get a message along the lines of:
“12.2222The Temp is 12.2222 degrees Celsius.”

Please, can someone explain why my result of the calculation is turning up twice? thanks.

Hi there, im no expert, but I had to put the code in parenthesis like this:

(tempc = (tempf - 32) / 1.8 );

That seemed to resolve the long weird error message for me. good luck!

std::cout << (tempc = (tempf-32)/ 1.8);

if you do (tempc = (tempf-32)/ 1.8);

without the std::cout << should work fine.

I keep getting an error saying a ‘;’ is expected before ‘std’. I have a ‘;’ at the end of 1.8 and before ‘std’. What am i doing wrong? Also, i would’ve cut and pasted the error message but it doesn’t seem to be allowed?

#include

int main() {

double tempf = 72.0;
double tempc;
tempc = (tempf - 32) / 1.8;

std::cout << “The temp is” << tempc << “degrees Celsius\n”;

}

Are you getting an error when you compile the code, or when you click “Run”? The lesson wants the message to be exactly as directed. From your post it appears you are missing a space after “is” and also before “degrees”. There should be a period following “Celsius” as well. When you paste code into a post, please format it as code by clicking on the </> icon first, and then pasting your code in the space specified. That will preserve formatting, and allow special characters from your code to show up. For example:

#include <iostream>

Hope this helps! If not, post your code again. Good luck!

1 Like
#include <iostream>

int main() {
  double tempf=83.0;
  double tempc;
  tempc=(tempf-32)/1.8;
  std::cout << "The temp is " << tempc << " degrees Celcius.\n";
  
  
  
  
  
  
  
}

can someone tell me where the mistake is?
thank you

Check your spelling of the word “Celsius.” :wink:

2 Likes

Im not getting any compile errors, but there is no output when i run this code.

#include

int main() {
double tempf = 85.0;
double tempc;

tempc = (tempf - 32) / 1.8;

std::cout << "The temp is " << tempc << " degrees Celsius.\n";

}

4 posts were split to a new topic: [FIXED] C++ undefined reference to main

This is failing step 3 and I don’t know why?

1 Like