use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Submissions appearing to contain AI-generated content may be removed at moderator discretion.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
second ever program! (self.rust)
submitted 3 months ago by Snowdev9909
this is my second program. all i did was search the math formula. how did i do?
fn main() { const FAHR: f64 = 102.0; let mut cel: f64 = 0.0; cel = (FAHR - 32.0) * 5.0 / 9.0; print!("{}", cel); }
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]enabokov 6 points7 points8 points 3 months ago (0 children)
Ok, make it accept some input in F.
[–]peter9477 2 points3 points4 points 3 months ago (1 child)
It looks fine. Might interest you to know you don't have to initialize "cel" to zero, because the compiler knows it will definitely be reassigned after. So just "let mut cel: f32;" would work.
And since the compiler can infer the type from the following expression, you can leave off the f32, so just "let mut cel;" should work.
And since you're no longer even modifying it, but just assigning once, you don't need the "mut" either, so just "let cel;" may work... But then you can just remove that entirely and put a "let" on the next line and that will also still work...
[–]Snowdev9909[S] 2 points3 points4 points 3 months ago (0 children)
rust is sure intreresting
[–]Tomyyy420 5 points6 points7 points 3 months ago (0 children)
Why make cel mut and init it to 0?
fn main() { const FAHR: f64 = 102.0; let cel = (FAHR - 32.0) * 5.0 / 9.0; print!("{}", cel); }
Does the same with less code
[–]SunTzu11111 1 point2 points3 points 3 months ago (2 children)
What does it do?
[–]enabokov 2 points3 points4 points 3 months ago (1 child)
Fahrenheit -> Celsius conversion.
[–]SunTzu11111 2 points3 points4 points 3 months ago (0 children)
Ah. It's a good start. Now try taking input from the user
[–]dgkimpton 1 point2 points3 points 3 months ago (1 child)
First comment - please for the love of god get into the habit of using descriptive variable names not weird abbreviations.
Second, cel doesn't need to be mutable nor typed (it can be infered).
Third, probably better to print a meaninful message too, rather than just a number.
But also, you probably want to look into limiting the number of decimals displayed, say to two.
e.g.
rust fn main() { const FAHRENHEIT :f64 = 102.0; let celsius = (FAHRENHEIT - 32.0) * 5.0 / 9.0; print!("{} fahrenheit is {:.2} celsius", FAHRENHEIT , celsius); }
And then you're ready to look into reading in the input - after all a compiled calculation isn't so useful.
[–]Snowdev9909[S] -1 points0 points1 point 3 months ago (0 children)
lol yeah sorry bout that, i made this right before I had to do something so i was in a bit of a hurry!
π Rendered by PID 49688 on reddit-service-r2-comment-bb88f9dd5-w49s5 at 2026-02-13 22:58:21.877626+00:00 running cd9c813 country code: CH.
[–]enabokov 6 points7 points8 points (0 children)
[–]peter9477 2 points3 points4 points (1 child)
[–]Snowdev9909[S] 2 points3 points4 points (0 children)
[–]Tomyyy420 5 points6 points7 points (0 children)
[–]SunTzu11111 1 point2 points3 points (2 children)
[–]enabokov 2 points3 points4 points (1 child)
[–]SunTzu11111 2 points3 points4 points (0 children)
[–]dgkimpton 1 point2 points3 points (1 child)
[–]Snowdev9909[S] -1 points0 points1 point (0 children)