Variables Arithmetic IO

we often need to show a specific number of digits

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gt;; cu < "ne a0frFLE ayhn es frTU:" ot < Etr o AS, ntig le o RE ; cn> p i >; The function c nonly collects input up to the first space or newline. i c ncan i be used to obtain multiple inputs. It knows when to delimit (i.e. start looking for the next input) when it reaches a space or newline (or tab). Here's the same example as above, but using just one c n i: dul a obe ; itx n; bo p ol ; cu < "ne adcml itgr adboenvle " ot < Etr eia, nee, n ola au: ; cn> a> x> p i> > >; We can get strings in the usual way: srn wr; tig od cu < "ne awr:" ot < Etr od ; cn> wr; i > od However, using that technique, you cannot get strings that have spaces. To get strings that have spaces in them, we have to use this method: srn s tig ; / gtawoeln o tx fo teue adsv it tevral s /e hl ie f et rm h sr n ae no h aibe gtiecn s; eln(i, ) That method gets a whole line of text, which could have spaces. Printing with precision When printing "floating-point values" (such as floats, doubles, etc.) we often need to show a specific number of digits after the decimal point. This is known as the "precision" of the number. The actual precision of the value will not change; we will only change the printed precision. The following will show three digits after the decimal point: cu.rcso() otpeiin3; cu.efis:ie,is:lafed; otst(o:fxd o:fotil) Here is a complete example: #nld <otem icue isra> uignmsaesd sn aepc t; itmi( n an) { dul x obe ; cu <...
View Full Document

Ask a homework question - tutors are online