Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- int rand_ab(int min, int max)
- {
- int bm = max - min + 1;
- int gr = RAND_MAX - (RAND_MAX % bm);
- int rnd = rand();
- while(rnd > gr) rnd = rand();
- return (rnd%bm)-min;
- }
- int main()
- {
- int n;
- char unos = ' ';
- FILE *f;
- f = fopen("igra.txt","w");
- while (unos != '0')
- {
- n = rand_ab(1,36);
- unos = getchar();
- if(n % 2 == 0)
- {
- if(unos == 'p')
- printf("Pogodak!\n");
- else if(unos == 'n')
- printf("Promasaj!\n");
- }
- if(n % 2 == 1)
- {
- if(unos == 'n')
- printf("Pogodak!\n");
- else if(unos == 'p')
- printf("Promasaj!\n");
- }
- if(unos != '0' && unos != 10)
- fprintf(f,"Random broj: %d, Korisnikov unos: %c\n", n, unos);
- }
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment