0

Any one can explain why this code give 17as result ,lcant understand how it work?

https://code.sololearn.com/c3Oed7nadH4a/?ref=app

22nd Jul 2017, 9:20 AM
esraa ragab
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 ☺
22nd Jul 2017, 10:10 AM
Irwin Lopez
Irwin Lopez - avatar
+ 3
all right man 😁😁😁
22nd Jul 2017, 10:12 AM
Irwin Lopez
Irwin Lopez - avatar
+ 2
@irwin lopez thats quite clear man.
22nd Jul 2017, 10:11 AM
shobhit
shobhit - avatar
+ 1
Use the "break;" Statement after each case block. otherwise the Programm will Run through all of them.
22nd Jul 2017, 9:27 AM
ILurch
ILurch - avatar
+ 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.
22nd Jul 2017, 9:51 AM
shobhit
shobhit - avatar
+ 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 :)
22nd Jul 2017, 10:30 AM
Saumya
Saumya - avatar
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'
22nd Jul 2017, 9:32 AM
Alex Sweetheart
Alex Sweetheart - avatar
0
thanks for all comments ,you help me more and i understand it now
23rd Jul 2017, 4:30 AM
esraa ragab