FAQ: Variables - Challenge: Temperature (Part 1)

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:

1 Like

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?

This is the solution, so there is no reason that should fail.

#include <iostream>

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

Something is rather amiss, here.

No, I just skipped it. I compiled locally and it was fine, so moving on and making a note here. I suspect its in there test coverage.

Hello, @psmilliorn.

Check the spelling of ‘degrees’ in your code (line 6). :wink:

2 Likes

Degress lol. Ok, I concede.

1 Like

For this project, I know it asks you to declare the variable tempc before setting tempc= (tempf-32)/1.8, but in real life, you could just do double tempc= (tempf-32)/1.8; right? Or do you first have to declare this variable and then later initialize it?

Hello, @chip2439329534.

Welcome to the forums.

Yes. You could declare and initialize the variable on a single line.

1 Like

hello!
please i would like to know how this commands work, like for the temperature conversion, “double” was written. my question is that is it necessary to write to the double and also whats the command use?

The codecademy has an article you can review on data types. This explains why you must include double in the variable declaration.

For details on double, take a look at the description of double on this page:
https://docs.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=vs-2019

hello there, i know this is late but i think there are still people who are looking for the solution. i tried naming the compiled file “g++ temperature.cpp -o temperature” then execute it and it did the work for me, i hope this help.

SOLVED: The solution is very specific (as it should be, I suppose). Make sure you are not outputting your own file name when compiling the code. For example:
$ g++ temperature.cpp -o temperature //correct
not
$g++ temperature.cpp -o temp //incorrect


#include <iostream>

int main() {

  double tempf = 80.0;

  double tempc;

  tempc = (tempf-32)/1.8;

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

}
/*
Error: Did you type the commands correctly?
Every step is green with the exception to the Compile and Execute the Program in which I typed in the terminal:
*/
$g++ temperature.cpp -o temp
$./temp
The temp is 26.6667 degrees Celsius.

Does anyone know why this isn’t working?
#include

int main() {

double tempf = 50;

double tempc = (tempf-32)/1.8;

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

}
Bash:
$ g++ temperature.cpp
temperature.cpp: In function ‘int main()’ :
temperature.cpp:13:1: error: expected ‘;’ before ‘}’ token
}
^

It actually says
#include
not just
#include