1 / 10

Formatting output: integers

Formatting output: integers. Field: a group of columns in which results are printed is called a field Field width: The number of columns in the field writeln(IntId:##) IntId is an integer identifier or value

Download Presentation

Formatting output: integers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Formatting output: integers • Field: a group of columns in which results are printed is called a field • Field width: The number of columns in the field • writeln(IntId:##) • IntId is an integer identifier or value • ## is the rightmost column to print the integer (Compiler will ignore this value if its smaller than number of digits) • can be written as any integer expression • default is one

  2. Formatting output: reals • Writeln (RealId:#1:#2) • RealId is a real identifier or value • #1 is the rightmost column to print the real • #2 is the number of digits you want on the right of the decimal point. • If #2 is omitted, scientific notation is used

  3. Formatting output: strings • Writeln (stringId:##) • stringId can be a string or character identifier or value • ## is the rightmost column for the string to be printed in

  4. Formatting output: Boolean • Similar to strings • note: Although the compiler is not Cap sensitive, it always prints Boolean values in all CAPS.

  5. More on Readln:numerical values • Note: ENTER key counts sends a carriage return and a line feed to the computer • definition: “white space”: space, tab, carriage return, line feed • white space is used to delimit integers and reals

  6. Read vs. Readln • Readln is like Writeln: After the command is complete, the program’s “input or output pointer” moves to the next line • Writeln: next output placed on the next line • Readln: next input comes from the next line (this means the rest of the input on the original line will be ignored)

  7. Read vs. Readln (con’t) • Read is like Write: After the command is complete, the program’s “input or output pointer” stays on the same line • Write: next output placed immediately to the right of previous output • Read: next input comes from the next (on the right) character that was entered by user (note: input is not always entered by a user)

  8. Reading Characters • No delimiters can be used because white space characters are valid characters • We will skip section 4.6

  9. Reading Strings • Use readln for strings - NEVER use read • readln reads the whole line except CR/LF • If the number of characters in the string is less than the length of the string variable, the entire string is assigned to the variable. • If the number of characters in the string is more than the length of the string variable, the computer will assign as many characters as can fit in the variable beginning with the first character

  10. Reading strings and numbers together • If you need to read both strings and numbers in the same line, you should read the numbers first.

More Related