Variables Arithmetic IO

Tbepos tbepos ed ot nme f alson alson nl cu ubro

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: a } Conversion example This code converts teaspoons to other units of measurement. #nld <otem icue isra> uignmsaesd sn aepc t; itmi( n an) { ittapos n eson; cu < "laeetrtenme o tapos " ot < Pes ne h ubr f eson: ; cn> tapos i > eson; itglos=tapos(*628; n aln eson/31**) tapos- glos(*628; eson = aln*31**) itpns=tapos(*62; n it eson/31*) tapos- pns(*62; eson = it*31*) itcp =tapos(63; n us eson/1*) tapos- cp*1*) eson = us(63; ittbepos=tapos3 n alson eson/; tapos- tbepos3 eson = alson*; cu < "ubro glos "< glos< ed; ot < Nme f aln: < aln < nl cu < "ubro pns "< pns< ed; ot < Nme f it: < it < nl cu < "ubro cp:"< cp < ed; ot < Nme f us < us < nl cu < "ubro tbepos "< tbepos< ed; ot < Nme f alson: < alson < nl cu < "ubro tapos "< tapos< ed; ot < Nme f eson: < eson < nl rtr 0 eun ; } Simple user input You remember using c u to display a message. You can use c nto do the opposite: get input ot i from the user. It works like this (notice the > of c n which are opposite those of c u ): > i, ot itx n; cu < "iem anme:" ot < Gv e ubr ; cn> x i >; cu < "o gv m tenme "< x< ed; ot < Yu ae e h ubr < < nl You can use c nfor integer types, floating point types, string types, and others. It's easiest if you i ask the user to enter one value at a time, pressing Enter between each value. To acquire multiple values at once, just string them together with c n i: itx n; dul y obe ; sotz hr ; cu < "ne trenmrcvle:" ot < Etr he uei aus ; cn> x> y> z i> > >; This is equivalent to: itx n; dul y obe ; sotz hr ; cu < "ne trenmrcvle:" ot < Etr he uei aus ; cn> x i >; cn> y i >; cn> z i >; More examples: dul a obe ; itx n; bo p ol ; cu < "ne adcmlvle " ot < Etr eia au: ; cn> a i >; cu < "ne a itgrvle " ot < Etr n nee au: ; cn> x i &...
View Full Document

This note was uploaded on 05/23/2013 for the course CSE 202 taught by Professor Staff during the Winter '12 term at Ohio State.

Ask a homework question - tutors are online