Now that you know how to write text to the console, wouldn't it be interesting, to print out some actual calculations?


The printf() command doesn't just print out text, it also can replace placeholders. Those placeholders are marked by the percent-symbol % followed by a letter for the type. The letter %d incidates to print whole numbers and %f for decimal numbers. The numbers you want to substitute have to be placed behind the quotes separated by commas.

So the line printf("%f", 6.0); will write the number 6.000000. It is important to write .0 or any other decimal, when printing decimal numbers, otherwise it will only print out 0.

But you can do more. Instead of numbers you can use basic calculations like additions and multiplication, e.g., you can write 2+2*3 and the computer will replace this with the result 8 before it prints the value.


Your task is to calculate you body mass index (BMI) and write it to the console. The BMI is calculated by dividing your mass in kg by the square of your length in meters.