This bad, bad printf()

I had heard that she's a bad girl - but I did not expect such unbridled behavior :-))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int choice;
    do {
        printf("Your choice?\n");
        scanf(" %d", &choice);
    } while ((choice < 1) || (choice > 5));

    printf("The choice is %d.",choice);
    return 0;
}


https://drive.google.com/file/d/1rrHsnt330IBChoOtLN2yEwV_ynW1RlO0/view?usp=sharing

I like this :-)

https://drive.google.com/file/d/1RlCrwXeSyV-Q45cab73Fj89lZ3i6Qczg/view?usp=sharing


P.s. There is something murky between the interaction of this function with do-while at the compiler level. Do-While can be wild too ;-)

https://drive.google.com/file/d/11CH4mgT7qf4xW4yK0Iwh0QDFlXIz5RTf/view?usp=sharing
Last edited on
It's more a problem of the site cpp.sh than printf(...).
There is nothing 'wrong' with the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int choice;
	do {
		printf("Your choice?\n");
		scanf(" %d", &choice);
	} while ((choice < 1) || (choice > 5));

	printf("The choice is %d.", choice);
	return 0;
}


eg


Your choice?
0
Your choice?
0
Your choice?
6
Your choice?
6
Your choice?
3
The choice is 3.


If you want an on-line compiler, try repl.it
May be you are right coder777. Its cpp.sh site problem. They'll fix it, I guess, if they haven't already.

seeplus, are you accuse me of forgery and photoshop:-))) and thanks for the offer, I like this one ;-)
Last edited on
Topic archived. No new replies allowed.