fork(1) download
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int arr[5], n=4;
  7. clock_t start, end;
  8. double time_taken;
  9. void easy(), hard();
  10. char input, choice;
  11. FILE * fPointer;
  12. int main(void)
  13. {
  14. start=clock();
  15. printf("WELCOME TO MASTERMIND!\n");
  16. printf("\nDifficulty: [E]asy/[H]ard:\n");
  17. beginning:
  18. scanf("%c", &input);
  19.  
  20. if(input=='E' || input=='e')
  21. {
  22. printf("\nEasy mode. None of the digits repeat.\n");
  23. easy();
  24. end=clock();
  25. time_taken = (end-start)/CLOCKS_PER_SEC;
  26. printf("\nTime taken: %f seconds\n", time_taken);
  27. fPointer = fopen("save.txt", "w");
  28. fprintf(fPointer, "%f", time_taken);
  29. fclose(fPointer);
  30. }
  31.  
  32.  
  33. else if(input=='H' || input=='h')
  34. {
  35. printf("\nHard mode. Digits might repeat\n");
  36. hard();
  37. end=clock();
  38. time_taken = (end-start)/CLOCKS_PER_SEC;
  39. printf("\nTime taken: %f seconds\n", time_taken);
  40. fPointer = fopen("save.txt", "w");
  41. fprintf(fPointer, "%f", time_taken);
  42. fclose(fPointer);
  43. }
  44.  
  45. else
  46. goto beginning;
  47.  
  48. printf("\n\nPlay again? [y/n]: ");
  49. again:
  50. scanf("%c", &choice);
  51. switch(choice)
  52. {
  53. case 'y': printf("\nDifficulty: [E]asy/[H]ard:\n") ; goto beginning;
  54. case 'n': return 0;
  55. default: goto again;
  56. }
  57. return 0;
  58. }
  59.  
  60.  
  61. void easy()
  62. {
  63. int x, ran[4];
  64. srand(time(NULL));
  65.  
  66.  
  67. ran[0]=rand() %10;
  68.  
  69. check2:
  70. ran[1]=rand() %10;
  71. if( ran[1]!=ran[0])
  72. {
  73. }
  74.  
  75. else goto check2;
  76.  
  77. check3:
  78. ran[2]=rand() %10;
  79. if((ran[2]!=ran[1] )&& (ran[2]!=ran[0]))
  80.  
  81. {
  82. }
  83. else goto check3;
  84.  
  85. ran[3]=rand() %10;
  86. if((ran[3]!=ran[2]) && (ran[3]!=ran[1]) && (ran[3]!=ran[0]))
  87. {
  88. }
  89.  
  90. for(x=0;x<4;x++)
  91. {
  92. printf("%i", ran[x]);
  93. }
  94.  
  95. }
  96.  
  97.  
  98. void hard()
  99. {
  100. int x, ran[4];
  101. srand(time(NULL));
  102.  
  103. for(x=0;x<4;x++)
  104. {
  105. ran[x]=rand() %10;
  106. printf("%i", ran[x]);
  107. }
  108.  
  109. }
  110.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty