ICS2O_0X02_stringFormatting

Trying to output strings and real numbers in columns is difficult unless you use Turing's built-in string formatting.

Strings and numbers can be printed to the screen within fields of specified widths. If your data is smaller than the specified width, Turing will add spaces in order to reach the width you want. You can use this to set up your output in columns.

Remember: Strings are going to be left-justified in their field Remember: Numbers are going to be right-justified in their field

HOW? Add a colon and a number to your put command var itemName : string := "The rain in space" var quantity : int := 12 var total : real := 123.4567

put itemName : 40 %Turing adds enough spaces to make itemName be 40 spaces wide put quantity : 15 %Turing adds enough spaces to make quantity be 15 spaces wide put total : 15 : 2 %Turing adds enough spaces to make total be 15 spaces wide and also 2 decimal places