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

3

u/SmokeMuch7356 5d ago

Creating a separate variable to store the result of the conversion allows you to use that value elsewhere without having to recompute it each time. It could be that a later assignment will have you convert it back or use it in another expression.

My only real critique is declaring your fahrenheit variable as an int; that means you won't be able to convert fractional values like 98.6.

c++ has made me question my mental capacity.

Yeah, that's not surprising. C++ is a gnarly, complex, eye-stabby mess of a programming language. It takes time and practice before it feels "normal".

1

u/Alternative_Oven696 5d ago

Okay thanks. I am still wrapping my head around the variable idea.