Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<windows.h>
- int unit(int x);
- int ten(int x);
- int hndr(int x);
- int main()
- {
- int a,b,c,d,e,f,x,y,z,bull=0,cow=0,score=1000,l=1;
- while(l==1)
- {
- d=rand();
- e=d%900+100;
- a1=unit(e);
- b4=ten(e);
- c1=hndr(e);
- printf("random=%d%d%d",c,b,a);
- while(bull<3&&score>0)
- {
- printf("ENTER YOUR 3-DIGIT NUMBER\n");
- scanf("%d",&f);
- x4=unit(f);
- y5=ten(f);
- z1=hndr(f);
- printf("entered=%d%d%d",z,y,x);
- if(x==a)
- bull++;
- if(x==b)
- cow++;
- if(x==c)
- cow++;
- if(y==a)
- cow++;
- if(y==b)
- bull++;
- if(y==c)
- cow++;
- if(z==a)
- cow++;
- if(z==b)
- cow++;
- if(z==c)
- bull++;
- score=score-25*bull-50*cow-(3-bull-cow)*75;
- printf("bulls=%d\ncows=%d",bull,cow);
- }
- if(bull==3)
- printf("CONGRATULATIONS! YOUR SCORE=%d",score);
- if(score==0)
- printf("YOU LOST!\n BETTER LUCK NEXT TIME");
- printf("ENJOYED THE GAME? WANNA PLAY ONCE MORE? y/n 1---yes 2---no");
- scanf("%d",l);
- }
- getch();
- return 0;
- }
- int unit(int e)
- {
- return(e%10);
- }
- int hndr(int e)
- {
- return(e/100);
- }
- int ten(int e)
- {
- int b,c,a;
- c=hndr(e);
- a=unit(e);
- b=(e-c*100-a)/10;
- return(b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement