Advertisement
Guest User

Untitled

a guest
May 30th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<windows.h>
  4. int unit(int x);
  5. int ten(int x);
  6. int hndr(int x);
  7. int main()
  8. {
  9. int a,b,c,d,e,f,x,y,z,bull=0,cow=0,score=1000,l=1;
  10. while(l==1)
  11. {
  12. d=rand();
  13. e=d%900+100;
  14. a1=unit(e);
  15. b4=ten(e);
  16. c1=hndr(e);
  17.  
  18. printf("random=%d%d%d",c,b,a);
  19. while(bull<3&&score>0)
  20. {
  21. printf("ENTER YOUR 3-DIGIT NUMBER\n");
  22. scanf("%d",&f);
  23. x4=unit(f);
  24. y5=ten(f);
  25. z1=hndr(f);
  26. printf("entered=%d%d%d",z,y,x);
  27. if(x==a)
  28. bull++;
  29. if(x==b)
  30. cow++;
  31. if(x==c)
  32. cow++;
  33. if(y==a)
  34. cow++;
  35. if(y==b)
  36. bull++;
  37. if(y==c)
  38. cow++;
  39. if(z==a)
  40. cow++;
  41. if(z==b)
  42. cow++;
  43. if(z==c)
  44. bull++;
  45. score=score-25*bull-50*cow-(3-bull-cow)*75;
  46. printf("bulls=%d\ncows=%d",bull,cow);
  47. }
  48. if(bull==3)
  49. printf("CONGRATULATIONS!     YOUR SCORE=%d",score);
  50. if(score==0)
  51. printf("YOU LOST!\n BETTER LUCK NEXT TIME");
  52. printf("ENJOYED THE GAME? WANNA PLAY ONCE MORE? y/n  1---yes  2---no");
  53. scanf("%d",l);
  54. }
  55. getch();
  56. return 0;
  57. }
  58.  
  59. int unit(int e)
  60. {
  61. return(e%10);
  62. }
  63. int hndr(int e)
  64. {
  65. return(e/100);
  66. }
  67. int ten(int e)
  68. {
  69. int b,c,a;
  70. c=hndr(e);
  71. a=unit(e);
  72. b=(e-c*100-a)/10;
  73. return(b);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement