fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int input_switcher(int input, int answer)
  6. {
  7. if (input == answer) {return 1;}
  8. else if(input < answer) {return 2;}
  9. else if(input > answer) {return 3;}
  10. else {return 0;}
  11. }
  12.  
  13. int main(void)
  14. {
  15. int input, answer, tries;
  16. char keepGoing = 'J';
  17. srand((int)time(0));
  18.  
  19. while(42)
  20. {
  21. input = 0, tries = 0;
  22. answer = 1;//rand()%100+1;
  23.  
  24. printf("Jag \"t\x84nker\" p\x86 ett tal mellan 1 och 100, gissa vilket!\n");
  25.  
  26. while(42)
  27. {
  28. printf("Gissning: ");
  29. scanf_s("%d", &input);
  30.  
  31. switch (input_switcher(input, answer))
  32. {
  33. case 1:
  34. printf("Grattis, det var r\x84tt!\n");
  35. printf("Du gjorde %d f\x94rs\x94k.", tries);
  36. break;
  37. case 2:
  38. printf("Du gissade f\x94r l\x86gt, f\x94rs\x94k igen!\n");
  39. tries++;
  40. break;
  41. case 3:
  42. printf("Du gissade f\x94r h\x94gt, f\x94rs\x94k igen!\n");
  43. tries++;
  44. break;
  45. default:
  46. break;
  47. }
  48. if(input == answer) {break;}
  49. }
  50. printf("Ska vi spela en g\x86ng till(J/N)? ");
  51. scanf_s(" %c", &keepGoing);
  52. if(keepGoing == 'N' || keepGoing == 'n') {return 0;}
  53. else if(keepGoing == 'J' || keepGoing == 'j') {system("cls");}
  54. }
  55. return 0;
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
1
6
0
N
compilation info
prog.c: In function ‘main’:
prog.c:29:17: warning: implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration]
                 scanf_s("%d", &input);
                 ^
/home/C1VpEF/ccgJCqoE.o: In function `main':
prog.c:(.text.startup+0x7e): undefined reference to `scanf_s'
prog.c:(.text.startup+0xc6): undefined reference to `scanf_s'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty