- 2

Any help please

I don't understand why it's not printing case 3. #include <stdio.h> main(){ int number=0; while(number<5) { switch (number) { default: printf("defualt\n"); case 0 : printf("cas 0\n"); break; case 3 : printf("cas 3\n"); break; case 2 : ++number; case -1 : printf("cas -1\n"); break; case 1 : printf("cas 1\n"); } ++number; } return 0; }

10th Apr 2020, 6:30 PM
فتحي حمد
فتحي حمد - avatar
10 Answers
0
case 3 is not printed because in case 2 number is incremented to 3, but after the switch statement number is incremented again (to 4)
10th Apr 2020, 7:00 PM
John Robotane
John Robotane - avatar
+ 3
Please don't just post code - communicate! What is your code supposed to do? What happens instead? What have you tried to fix it? How can we help you?
10th Apr 2020, 6:47 PM
HonFu
HonFu - avatar
+ 2
what is wrong with that code? a function must have a return type (void if it doesn't return something) you returned 0 at the end of the code, so you should also add the return type (int) to de function definition int main () { ...
10th Apr 2020, 6:48 PM
John Robotane
John Robotane - avatar
+ 2
Mention complete detail what output you want through this code and what i have to fix in this code and choose relevant tag according to your problem.
12th Apr 2020, 12:26 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
The only thing I can see is "wrong/missing" is a "break" in case 2 so it falls though to case -1......but without knowing what you'r trying to do...It's had to say. edit..and a "break" at the default as it's not at the end of the switch.
10th Apr 2020, 6:51 PM
rodwynnejones
rodwynnejones - avatar
0
Just I found in axm I don't understand why not printing case 3
10th Apr 2020, 6:55 PM
فتحي حمد
فتحي حمد - avatar
0
What should be the output
10th Apr 2020, 6:59 PM
فتحي حمد
فتحي حمد - avatar
0
You'r incrementing at case 2 as well as at the end.
10th Apr 2020, 6:59 PM
rodwynnejones
rodwynnejones - avatar
0
@John Robotane that's probably just missing when the code was mis-copied and pasted onto here.
10th Apr 2020, 7:03 PM
rodwynnejones
rodwynnejones - avatar
0
ya
12th Apr 2020, 12:29 AM
OMNYA OSAMA
OMNYA OSAMA - avatar