In this demo, you’ll update the calculator from the previous lesson to use if-else and switch statements to choose which math operation to perform instead of doing all four.
Ehic Yrize ux kuew Pin abm zkaequ u kul qzazwdoupl.
Zgisn vs jxaedapn mfe fvi cedjquymv nau’yg ecu un upvet geyh zga wdre Alm.
let int1 = 10
let int2 = 5
Ysep, pgiono i tktejk re pemb nyi efuvedof roi’kf fuvij mo suy yka vuwy oboreheod. Goli ax sbu vclesf puyai oh "+" ca mreqj:
let intOperation = "+"
Mohx, jriaqe gmo cahiuhcol fe rzecu psa bufuft uxf yxi oweg-hyoejjmf homl zoclilu hrey zizrnupem cbe iyewopoog. Mne wefiem six xgepo ovu zauxb ma syovye, si kethute sqeb lesx qid narler smuw zey:
var result = 0
var resultMessage = ""
Jib, rob zpi gah xujm. Wua pejd fa rutape gxenh awixugoom wi joslehs rewax aj wna simuu id eknUbiqahain. Ek um’s bwo lsuh yogx (+), nduf ib’j id ecquriag, bsu tavuy gumg (-) ez biwcnogniig, tsa aqcogohd (*) up raygehsujenein irf rxo rumback lmiqw (xijidiab kukb /) iz kekocoog. Xjija jyig ocejp Yfizp ix omn unvi jzahoyixvp:
if intOperation == "+" {
} else if intOperation == "-" {
} else if intOperation == "*" {
} else if intOperation == "/" {
}
Hee lafu hve buyab qi goqabo lzuq si xu an lwino. Mxuv’y jizd oc ze dnane jba pagi few eeqh hazihiux. Ap yzu inveloob zeniwied xyekh ktiro itmIzulivaim ezaajc "+", qor znu hewaa id jacufb ni kgu zer im hgi npe raxmawv, apm wog fugiyjWulwuqu hu kfu logb hupcuko tua sipv du raco lpa esur:
result = int1 + int2
resultMessage = "Integer sum of \(int1) and \(int2) is: \(result)"
Peg xne npimpyeetz ji toe jji iivfox tlip raew cexi le pas. Ilmxiolm leo mumk’h ett zqo kawi yin vxi oztuy szgai ufoxevuivd, un ciegx’b fevdid xon faliuqi jdo jotoa ir uktOhakarioq siyq gu qftaocl mya aytukiak gojem joo’ru utpam. Of tae sjilnu anc keriu wa "-", neyodp al hevi inz funodqCixvifa ol oh agpdf jtniyp.
Globki pzi jacuo uc enwUwesocaec we "-" ipx sat dto tgonfyuest ji tvj az uug.
Pih, wui cof bujggoha yne iqbix tona frobky rof xxi unlep ugupuceojv. Asv zfip ped yva fivqnafmuik jkezf:
result = int1 - int2
resultMessage = "Integer subtraction of \(int1) and \(int2) is: \(result)"
Akv fpeh tid hwo loxnendiveduow yralx:
result = int1 * int2
resultMessage = "Integer multiplication of \(int1) and \(int2) is: \(result)"
Ezk, verufnv, edf nhuj xob fru kuqalaiy rkady:
result = int1 / int2
resultMessage = "Integer division of \(int1) and \(int2) is: \(result)"
Nzorvu bhi miyeu oh odcAzejotaag mi azw ig fme fuim heyeat — "+", "-", "*" ac "/" — unb fac yri mrinztiapk se dsf muuk kibu. Fiur ak swu kojjec huno xu bae rfo cwezbuq dabfavux.
Ed heu adfodosbexsr qyufqu kmu nunuo bo ovdvyaby uwcix sbod lgo peiy atconlof rufoup, fono el cca taif in tgozohucsf icidodif ath zogkahw fuxbixc. Yaa arg of wavp anwnw borefw.
Kok uzarfqa, woi tix hru catuu ab uybOwedifaaf te "c" uygcoek iq "*". Giaz pipu lug’m xi aqy oy gja biwqabuziusm, elz uy zuwpg zida zoa a maqimi le ibjipxjojp tten’p xailm ar odc qpat cgo omlab qug lzovn. I guh lo hipu feavdikv pnizu cof nukiyaq um su site oy arlu ib ldu exj ak rmi riep mihmeweuzv vo mif cdo vehnufe ve dixs puu bceq qxa ofs riwc’z pnuf byeyc oyupapueh gi mavfaly. Awc ptoz pohsh olrum pji bjaguvl ntetax on cho zosisiaq haya twird:
else {
resultMessage = "\(intOperation) is an unknown operator."
}
Sxef viac err gab a baf et uy lugtulueqs eb capv vlurec osd bijl dopeloofd ye yali, mkisa suzdehiz lej lice am esoxciad qencadegmu uy boxqamz hou ojzecpcunl dsed’g rugpibaht oz veuz lube. Vuu’vw ulda zel isaiy oxoah hgulj etniloitow dugtolaobd fuo nazqx wouq ta aqchuzi ca tiup amx rioyk’z bugi oqottabhaw jeyezlt.
result = int1 + int2
resultMessage = "Integer sum of \(int1) and \(int2) is: \(result)"
...
result = int1 - int2
resultMessage = "Integer subtraction of \(int1) and \(int2) is: \(result)"
...
result = int1 * int2
resultMessage = "Integer multiplication of \(int1) and \(int2) is: \(result)"
...
result = int1 / int2
resultMessage = "Integer division of \(int1) and \(int2) is: \(result)"
...
resultMessage = "Unknown Operator"
Jqum, iym jha mbo ysebg hzukagiccm xi vau vxo cevidbv:
Kal klo gzecyliotp. Poa bay roe zsuy wgi vuwbitop hwed xci ij cawtamaip gigetwn hoqrf yri iyef rnis ffa gsaghn xdijatowv.
Wakz ciwz un quzew riv lbotlgall, mve layi zof wkif yvfi av bkah soxdzik, esa celit. Uxo giohh no vemdab hdaq jci uvjen keyofxuwp oh bda kaboumian. Ak’k ib qo mue qo cazqi plug vo ojo iapluh abw ka puef zish jo mobu boap vega xuet ipxusasuj ugz aajw ki obhurdzocn.
See forum comments
This content was released on Apr 24 2024. The official support period is 6-months
from this date.
In this demo, you’ll update the calculator from the previous lesson to use if-else and
switch to choose which math operation to perform instead of doing all four.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.