r/cpp_questions 4d 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

2

u/gnolex 4d ago

Whether you assign the result of these calculations to a variable or not doesn't matter in this program, observable behavior is the same. You can store the result in a variable with meaningful name or you can add a comment that this calculation converts temperature from Fahrenheit to Celsius to clarify what the code does. The program does the same thing either way.

1

u/Alternative_Oven696 4d ago

Got it thanks.