FAQs on the exercise Challenge: Temperature (Part 2)
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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hi! For some reason, every time I do g++ temperature.cpp in the terminal, it says this error, g++ temperature.cpp temperature.cpp: In function ‘int main()’: temperature.cpp:10:3: error: expected ‘;’ bef
std::cin >> tempf; PLease help me thanks!
Unless we alter the control flow which you’ll learn more about as you progress, code is executed from top to bottom in our program. In your program, a value is assigned to tempc here:
So, what is the value? Well, tempf has been declared, but no value assigned: double tempf;. Therefore, we have (0 - 32) / 1.8 which equals: -17.7778.
Then, you ask for the user to input a temperature in Fahrenheit, and assign that user input to the variable: tempf. After that you don’t use that value to re-calculate the value assigned to tempc, so tempc still has -17.7778 assigned to it.
You then print your output, using the value still assigned to tempc. What would happen if you get the user input first, and then calculate the value for tempc?
I wrote:
std::cout << “Enter the temperature in Fahrenheit: \n”;
std::cin >> tempf >> “\n”;
And something went wrong, but I don’t know why.
The correct is only:
std::cout << "Enter the temperature in Fahrenheit: ";
std::cin >> tempf;
I thought I had to use the “\n” at the end of each phrase.
Not sure if it is a bug or it is the compiler, or maybe this is how all C++ code is, but
When I write std::cout << “something " << var << " else.\n”;
If I miss a dot in between the else\n without deleting the entire line back to the missed dot, and just skip to it and enter the dot that I missed, the compiler fails to see the code is correct. I am wondering if this is a Codecademy thing, because the compiler fails to understand I have corrected the mistake, or do all compilers act like this, and I will get errors in my code if I skip to mistakes instead of deleting the entire line back to the mistake.
I think mine is a full bug exercises because in part one temperature is compiler shows files does not exist why does it shows this message in exercise block letters it shows the same message I again had to rewrite the whole file which took about 2 hours . Why does the compiler says temperature.cpp does not exist???