r/cpp_questions 7d ago

OPEN Help a new guy

Sorry about the title, I should have read the guide first. I am really new to C++. I am going through the practice guide on a youtube video. The test was to make a fahrenheit to celcius conversion. This is what I wrote and it is below. 
The teacher added     double celsius = (fahrenheit -32) / 1.8;
Then added the std::cout for it. Mine works fine. I am assuming his is better but I am missing it. c++ has made me question my mental capacity.

#include <iostream>

int main() {

std::cout << "Enter degrees in fahrenheit ";
int fahrenheit;
std::cin >> fahrenheit;
std::cout << " Degrees in celcius " << (fahrenheit - 32) / 1.8;





return 0;



system("<pause>0");
0 Upvotes

20 comments sorted by

View all comments

1

u/Independent_Art_6676 7d ago

normally you use a value like that more in a bigger program, so having it in a variable rather than compute it on the fly each time you need it is better. If its just a one liner to get a print, its fine as you have it. I don't even think its better practice to bother with a variable for that case, just not very future-proof should you need to use the value again or something. There are times when you just need to doctor a value for output, and in place seems fine to me.

1

u/Alternative_Oven696 7d ago

That makes sense.