Advertisement
Guest User

Untitled

a guest
May 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. void guesses(void)
  2. {
  3. int i = 0;
  4. int iprint = 0;
  5. char gone, gtwo, gthree, gfour;
  6. int none, ntwo, nthree, nfour, miss, hit = 0;
  7. for(i = 0; i <= globalguess - 1; i++ )//stops when i = globalguess because the mode
  8. {
  9. hit = 0;
  10. miss = 0;
  11. int guesscheck = globalguess - i;
  12. printf("write your guess(1-6 only,no ENTER is needed)\n");
  13. if(globalchoice == 4)//if its crazy mode print crazy mode
  14. {
  15. printf("CRAZY MODE!!!\n");
  16. }
  17. else
  18. {
  19. printf("%d guesses left\n", guesscheck);//print how many guesses you still have
  20. }
  21. gone = (int) getch() - 48;
  22. printf("%d", gone);
  23. gtwo = (int) getch() - 48;
  24. printf("%d", gtwo);
  25. gthree = (int) getch() - 48;
  26. printf("%d", gthree);
  27. gfour = (int) getch() - 48 ;
  28. printf("%d", gfour);
  29. //get the guess from the user
  30. if(gone != 1 && gone != 2 && gone != 3 && gone != 4 && gone != 5 && gone != 6 )
  31. {
  32. printf("\n1-6 only!!\n");
  33. i--;
  34. guesscheck = globalguess + i;
  35.  
  36. }
  37. else if( gtwo != 1 && gtwo != 2 && gtwo != 3 && gtwo != 4 && gtwo != 5 && gtwo != 6 )
  38. {
  39. printf("\n1-6 only!!\n");
  40. i--;
  41. guesscheck = globalguess + i;
  42. }
  43. else if( gthree != 1 && gthree != 2 && gthree != 3 && gthree != 4 && gthree != 5 && gthree != 6 )
  44. {
  45. printf("\n1-6 only!!\n");
  46. i--;
  47. guesscheck = globalguess + i;
  48. }
  49. else if( gfour != 1 && gfour != 2 && gfour != 3 && gfour != 4 && gfour != 5 && gfour != 6 )
  50. {
  51. printf("\n1-6 only!!\n");
  52. i--;
  53. guesscheck = globalguess + i;
  54. }
  55. // checking if the numbers aren't between 1-6
  56. else
  57. {
  58. none = (globalrand / 100) / 10;
  59. ntwo = (globalrand / 100) % 10;
  60. nthree = (globalrand / 10) % 10;
  61. nfour = globalrand % 10;
  62. //saperate the numbers to check the miss and hit
  63. if(gone == none)
  64. {
  65. hit = hit + 1;
  66. }
  67. if(gtwo == ntwo)
  68. {
  69. hit = hit + 1;
  70. }
  71. if(gthree == nthree)
  72. {
  73. hit = hit + 1;
  74. }
  75. if(gfour == nfour)
  76. {
  77. hit = hit + 1;
  78. }
  79. if(gone == ntwo || gone == nthree || gone == nfour)
  80. {
  81. miss = miss + 1;
  82. }
  83. if(gtwo == none || gtwo == nthree || gtwo == nfour)
  84. {
  85. miss = miss + 1;
  86. }
  87. if(gthree == ntwo || gthree == none || gthree == nfour)
  88. {
  89. miss = miss + 1;
  90. }
  91. if(gfour == ntwo || gfour == nthree || gfour == none)
  92. {
  93. miss = miss + 1;
  94. }
  95. //checking if there is hits or misses
  96. iprint = i + 1;
  97. if(hit == 4)
  98. {
  99. i = globalguess;
  100. }
  101. //checking if the hits number is 4 if yes stop the loop
  102. else
  103. {
  104. printf("\nyou got %d HITS %d MISS\n", hit, miss);
  105. }
  106. } //print how many hits and how many miss
  107. }
  108. // after the loop
  109. if(i != globalguess)//check if the user won or lose
  110. {
  111. printf("\n 4 HITS YOU WON!!!\nIt took you only %d guesses, you are a professional code breaker!\n\n", iprint);//win
  112. }
  113. else
  114. {
  115. printf("\nOOOOHHHH!!! prancatius won and bought all of Hankkah's gifts\nnothing left for you....\nthe secret code password was %d\n\n", globalrand);//lose
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement