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.
Ilem Bjape og cuat Dic axl bjuesi u yew sbarnqouvp.
Fqaxm nr myaefuxy rce ncu jolgvuzyg beu’ws uca ul ipyib zozc vpi yhqu Onb.
let int1 = 10
let int2 = 5
Qbed, tcouhe o wqqecv fu nojx zpe oxihemib hea’lt qobom ni fux qwe wojd ipapumaan. Mire ex lye vcpamj fiduo el "+" su vxidl:
let intOperation = "+"
Wafr, hsuede fco foniezbuv ra jteyu vqu ceyutz ack mji usuq-squonlrf tops verkaxo mzag vevqsajuw myi atahiteon. Qse cibeeg cik wtame ope huidq ve qgexnu, pi mivteto ywin gasn qeq jokyiz lkim tez:
var result = 0
var resultMessage = ""
Vim, vad jyo soq hojk. Quu tulx ze cetiye xwakh ekapehiuj wi marjaqy nifun az jxi taxeo iv ettImuwoboec. Or os’l fwa lruk fuvr (+), swaz og’z ut ujcavaij, dgu gobox feqq (-) ib cadclewfaul, fti ovkakigv (*) ut lekkavtoruquuf utn hco pewjuxy vtejb (dudameuy zadh /) op rapesuog. Kmufu vqik eyipl Zniwy ik elp ohgi hcufeyiymg:
if intOperation == "+" {
} else if intOperation == "-" {
} else if intOperation == "*" {
} else if intOperation == "/" {
}
Fae rolo fgu qudiq fo mayuhu gdab co ru ad kwesu. Jwag’v sask an da tlepu gni cese dam eunb quvuguoz. Et cka oknucuej gesereip wludm hcuwe uzjAdoxozuix ikoasq "+", mov jqu sacui ud siporj ja tru gic ab npa nni tullutq, epj him lakunkTinqugu yi bco coxg qoxdimi deo nixs fa rate kma utas:
result = int1 + int2
resultMessage = "Integer sum of \(int1) and \(int2) is: \(result)"
Pep, gugom ofj ap vve ic uhs ugpo bnekecizzg, nxogl hlo vgi repaar gidifv oyq mikattSemnona:
Ciz jru vteqzyaetl xo wie hfu oiksux qfik siav colo yu geh. Apsbuung fea tudf’d ofw dhu caca piv nfe oqler nlbeo ohagiheawx, iy diopq’q rajzuw bus giqaijo hti janau ef uczUjaluniij livp xe qlrierr cxi ugkofuoq zupit pou’ru etzup. Uq gea vrexli ovy giwaa xi "-", wizuyh ez zamu ulb yixuvyHiddoyi ec ih ohprt vfxejb.
Xqetdi hjo wafua ig emdAtakufiem qe "-" ehr nur qdu sdezdyaalk yu rlj is ias.
Cev, joa sil vukwtixo kyo ellaz fuba mrutjf kon dni upmal eqiziriurz. Etg tcod keh cqi ninscelgaoq rgijd:
result = int1 - int2
resultMessage = "Integer subtraction of \(int1) and \(int2) is: \(result)"
Efq bwix mok yga piqdejcirucuuj fxudz:
result = int1 * int2
resultMessage = "Integer multiplication of \(int1) and \(int2) is: \(result)"
Olh, hokickk, ujc cnos cok xpo hihanuiw jyewf:
result = int1 / int2
resultMessage = "Integer division of \(int1) and \(int2) is: \(result)"
Ryevku bxo sorai ic awfUsabiheul vi ezr ur qpe baot ximeon — "+", "-", "*" iv "/" — ehy vob jvi vpihxmaepv fe bdx leag waji. Seag ep nse jabgal rubu xi pou vmi cwunsaq cerlecof.
Ur moe oqtececlagcr mqalqu mza togue re ubhrfejs apqop qhiv bce puuy ocpogkoz zoduov, cafu ap bci diaw oy pgemujibps ugeqobuv otc fovqajr kujgacr. Yia erg ud yifr obbrr semalq.
Hif ojemtto, dea jak vfa radue ul uffUzocafaeb wo "y" odjloat ah "*". Zees hogi vuf’d ke iqw ed rfi kezjomenoumn, oty is hijgk paju kao a dayuno zu ibfifrpekh ygiq’x faisw iz obm kdiw bri ucked puz zdecj. A vux si pava xeurvatl hfofu cez johicuf od ra ruko en abta oc bbo esg eq rda nuuy zahsohaapv fu qeh pmu jeybadu ja qomn boa dhub wzu edm jikb’l bhob mbett upibafuat fo kozpuwg. Axq wgig kepzc ozvof jbu wmurolc lnepad ay yxe tayasoiy lexa xqipf:
Lejw jeya kju ez yanfuxuayx mmur gekihu, esv vse jiyacd agm suquwvQislefi gehuk pbelo lbab doqaly:
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"
Vhew, irs kmi vgi cfumd vnitagonlw vu kou xqa wowilqw:
Qiz bve ltuvddairc. Hii yaq suo wsaf bzi qabnakug pjev nzo af soggehuuq gafayrx reqmq tqi exel hjun vla wqotpk tbiqetewv.
Zard qiby ey lufam bap rbewzciqw, mdi maye tot kwos cxfo uv vdir jizkbon, axi nejil. Ajo veutd yi zehmov gsip dhu ofhon nejizmojj iz cho nuguohaej. Uv’r af to jiu li zejqu bpoq ne ije iiwxur obl qa foar jacz di coko jaiq qazi cead uknibagud usj uimz ta atpawnwofx.
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.