DEV Community

Cover image for Rust: Day 3, Arithmatic
G-type
G-type

Posted on

Rust: Day 3, Arithmatic

Hello there developer community. This is my second day learning rust so I decided to try something simple. How do I add 20 and 30 together. So this is me trying to figure that out. I encounted some issues with the "Unique" variable types, Like what the hell is i32. But anyway. This is my first attempt.

fn main() {
    let a i32: 20;
    let b i32: 30;

    println!("{}", a + b);
}
Enter fullscreen mode Exit fullscreen mode

This is an example of apparently the wrong thing. Because to assign types you need to use let a: i32 = 20; but I didn't know this by the time I was learning this. The correct method of doing this is below.

fn main() {
    let a: i32 = 20;
    let b: i32 = 30;

    println!("{}", a + b);
}
Enter fullscreen mode Exit fullscreen mode

And this program outputs:

50
Enter fullscreen mode Exit fullscreen mode

Next post I am going to attempt conditional logic and function calling so well yeah, stay tuned. And lastly, I hope my suffering brings comfort to those who as well are learning rust that I may help you in your journey.

Top comments (0)