Pick 4 Predictor C code


SUBMITTED BY: Guest

DATE: March 11, 2014, 11:57 p.m.

FORMAT: Text only

SIZE: 3.9 kB

HITS: 1128

  1. ***********************************************************
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. int main()
  6. {
  7. FILE *in, *out;
  8. int i, j, k, temp, temp1, temp2, temp3, temp4, a, a1, a2, a3, a4;
  9. int arrayOf4[25] =
  10. {123,134,145,156,167,178,189,1234,1245,1256,1267,1278,1289,
  11. 2345,2356,2367,2378,2389,3456,3467,3489,4567,5678,5689,6789};
  12. int inArray[100], matchArray1[10], matchArray2[10], found = 0, possible;
  13. int numCount, score;
  14. /*
  15. ** Open
  16. */
  17. if((in = fopen("drawsP4.txt", "r")) == NULL)
  18. {
  19. printf("could not open drawsP4.txt\n");
  20. getch();
  21. exit(0);
  22. }
  23. if((out = fopen("out.txt", "w")) == NULL)
  24. {
  25. printf("could not open out.txt\n");
  26. getch();
  27. exit(0);
  28. }
  29. /*
  30. ** Start scanning
  31. */
  32. i = 0;
  33. while(!feof(in) && i < 50)
  34. {
  35. fscanf(in, "%d", (inArray + i));
  36. i++;
  37. }
  38. numCount = i;
  39. printf("Pairs to play are:\n");
  40. fprintf(out, "Pairs to play are:\n");
  41. start:
  42. for(i = 0; i < 25; i++)
  43. {
  44. possible = 0;
  45. score = 0;
  46. temp = arrayOf4[i];
  47. temp1 = temp/1000;
  48. temp2 = (temp - 1000*temp1)/100;
  49. temp3 = (temp - 1000*temp1 - 100*temp2)/10;
  50. temp4 = (temp - 1000*temp1 - 100*temp2 - 10*temp3);
  51. j = 0;
  52. for(j = 0; j < numCount; j++)
  53. {
  54. for( k = 0; k < 10; k++)
  55. {
  56. matchArray1[k] = 0;
  57. matchArray2[k] = 0;
  58. }
  59. a = inArray[j];
  60. a1 = a/1000;
  61. a2 = (a - 1000*a1)/100;
  62. a3 = (a - 1000*a1 - 100*a2)/10;
  63. a4 = (a - 1000*a1 - 100*a2 - 10*a3);
  64. matchArray1[temp1] = 1;
  65. matchArray1[temp2] = 1;
  66. matchArray1[temp3] = 1;
  67. matchArray1[temp4] = 1;
  68. matchArray1[a1]++;
  69. matchArray1[a2]++;
  70. matchArray1[a3]++;
  71. matchArray1[a4]++;
  72. score = 0;
  73. for(k = 0; k < 10; k++)
  74. {
  75. if(matchArray1[k] == 2)
  76. {
  77. score = score + 1;
  78. }
  79. }
  80. if(score < 3 )
  81. {
  82. possible++;
  83. }
  84. }
  85. if(possible == numCount)
  86. {
  87. printf("%d%d-", temp1,temp2);
  88. printf("%d%d-", temp1,temp3);
  89. printf("%d%d-", temp1,temp4);
  90. printf("%d%d-", temp2,temp3);
  91. printf("%d%d-", temp2,temp4);
  92. printf("%d%d\n", temp3,temp4);
  93. fprintf(out, "%d%d-%d%d-%d%d-%d%d-%d%d-%d%d\n",
  94. temp1, temp2, temp1, temp3, temp1, temp4,
  95. temp2, temp3, temp2, temp4, temp3, temp4);
  96. found = 1;
  97. }
  98. }
  99. if(found == 0)
  100. {
  101. numCount = numCount - 1;
  102. goto start;
  103. }
  104. printf("Enter any key to continue\n", numCount);
  105. getch();
  106. close(in);
  107. close(out);
  108. }

comments powered by Disqus