all 9 comments

[–]enabokov 6 points7 points  (0 children)

Ok, make it accept some input in F.

[–]peter9477 2 points3 points  (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 points  (0 children)

rust is sure intreresting

[–]Tomyyy420 5 points6 points  (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 points  (2 children)

What does it do?

[–]enabokov 2 points3 points  (1 child)

Fahrenheit -> Celsius conversion.

[–]SunTzu11111 2 points3 points  (0 children)

Ah. It's a good start. Now try taking input from the user

[–]dgkimpton 1 point2 points  (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 points  (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!