© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_2

2. Doing Arithmetic

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How to compute an arithmetic operation between integer numbers or between floating-point numbers

  • How to write a program containing several statements

  • How to print strings in several lines

Adding Integer Numbers

Let’s see how to compute the sum of two integer numbers ; for example, 80 and 34.

Put the following line as the only contents of the braces of the main function:

print!("The sum is {}.", 80 + 34);

The execution will print: "The sum is 114.".

The second argument of the print macro is the expression 80 + 34.

The compiler surely does not store in the executable such numbers ...

Get Beginning Rust: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.