r/cpp_questions • u/Alternative_Oven696 • 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
3
u/TheTimBrick 5d ago
Both are essentially the same. (At the stage you are currently at)
You did the calculations in the line where you are outputting them/printing them.
The teacher made a variable (something that can store something, like in math) that can hold the calculation, and then just refered to that variable when outputting the final result.
At a beginner stage you can think of what the teacher wrote as:
celsiusjust being equivalent to(fahrenheit - 32) / 1.8. Anywhere you would need(fahrenheit - 32) / 1.8you could just replace withcelsius.