0

Looping

1. BUG BUSTERS: What is wrong with this code? int counter = 100; while (counter < 10) { cout << “counter now: “ << counter; counter--; } 2. BUG BUSTERS: What is wrong with this code? cout << “Enter a number between 0 and 5: “; cin >> theNumber; switch (theNumber) { case 0: doZero(); case 1: // fall through case 2: // fall through case 3: // fall through case 4: // fall through case 5: doOneToFive(); break; default: doDefault(); break; } please identify the fault in Q1and 2 for me

10th Nov 2016, 3:20 PM
Rabbi Sarpong
3 Réponses
+ 2
1. simple loop don't work. 2. case 0 dont break. if 0 make case 0-5
10th Nov 2016, 4:08 PM
Вадим Глушков
Вадим Глушков - avatar
+ 1
first one does not work. second one is correct but if some one choose case 0 they will also get result from1-5 case. means two result. May be I am wrong.
10th Nov 2016, 4:10 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
syntactically it is correct. edit: I don't know what you want to do with this code, so I can't comment. May be some logical error.
10th Nov 2016, 3:45 PM
kamal joshi
kamal joshi - avatar