0
Any one can explain why this code give 17as result ,lcant understand how it work?
10 odpowiedzi
+ 4
😏because you have use x+=x 3 time
which mean x3+x3=x6, 3x+6x=9x, 3x+9x=12x
and at last you have add 5
12x + 5x= 17x
that's the reason ☺
+ 3
all right man 😁😁😁
+ 2
@irwin lopez thats quite clear man.
+ 1
Use the "break;" Statement after each case block. otherwise the Programm will Run through all of them.
+ 1
as said by others there is no break in your switch statement. for the first three times it keep on running as there is no break. after that on default case it was programmed to add 5 to total resulting in 17.
+ 1
switch case is an conditional statement; it contains block...!!!and break is an interating statement which passes the control when to the line after the loop ends and 'default' keyword is optional which executes when no value satisfies the case.
Rest to say bout the code ........i dont need to specify that again as already ppl ve specified it outstandingly so no need to repeat it .....hope dis info helps uh :)
0
Look here step by step:
https://code.sololearn.com/cL9yG5o09P4E/?ref=app
Every case after '3' works, while you don't use 'break', so that's the reason of '17'
0
thanks for all comments ,you help me more and i understand it now