Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define nl printf("\n")
- void game_rules();
- int generate_random(int min, int max);
- int show_result(int array1[],int array2[]);
- int coparation(int array1[], int array2[]);
- int main(int argc, char *argv[])
- {
- srand(time(NULL));
- int compare,i;
- int A[10];
- int B[10];
- int C[10];
- game_rules();
- nl;
- for(i = 0; i < 3; i++) {
- A[i] = generate_random(0,9);
- }
- puts("Enter 3 numbers from 0-9.");
- for (i = 0; i < 3 ; i++){
- scanf("%d",&B[i]);
- }
- nl;
- puts("Cheating numbers:");
- for (i = 0; i <3 ;i++)
- printf("+%d\n", A[i]);
- printf("Total sum is: %d. Which numbers computer imagined?\n",show_result(A,B));
- for(i = 0; i != 3 ; i++){
- scanf("%d", &C[i]);
- }
- compare = compare(A,C);
- switch(compare){
- case 1:
- puts("You scored one number!"); break;
- case 2:
- puts("You scored 2 numbers!"); break;
- case 3:
- puts("You scored 3 numbers!");break;
- default:
- puts("Imate nula pogodaka!"); break;
- }
- printf("Computer imagined this numbers :\n");
- for(i = 0; i < 3 ; i++)
- printf("%d\n", A[i]);
- system("PAUSE");
- return 0;
- }
- void game_rules() {
- puts("Dobrodosli u igru 'Pogodi broj' . Pravila igre su: \n 1. Unosite 3 brojeva. \n 2. Pogadjate koja je 3 brojeva zamislio racunar.");
- puts(" 3. Imajte u vidu da racunar zamislja redom x,y,z brojeve, a vi unosite redom a,b,c brojeve. ");
- puts(" 4. Nakon toga dobijate jedan broj u ovakvom obliku: ax + by + cz = r \n 5. Pogadjate brojeve x,y,c na osnovu zbira.");
- }
- int generate_random(int min, int max)
- {
- int random = rand() % ((max - min) + 1);
- return random;
- }
- int show_result(int array1[],int array2[]) {
- int x,y,z,result;
- x = array1[0] * array2[0];
- y = array1[1] * array2[1];
- z = array1[2] * array2[2];
- result = x + y + z;
- return result;
- }
- int komparacija1(int array1[],int array2[]) {
- int i,j,case,case2,sum = 0;
- for(i = 0;i <1 ;i++)
- for(j = 0; j< 3 ;j++) {
- if (array2[i] == array1[j]) {
- sum += 1;
- case = j;
- j +=2 ;
- }
- }
- for(i = 1;i <2 ;i++)
- for(j = 0; j< 3 ;j++) {
- if ((case == 0) && (j == 0)) j += 1;
- if ((case == 1) && (j == 1)) j += 1;
- if ((case == 2) && (j == 2)) j += 1;
- if (array2[i] == array1[j]) {
- sum += 1;
- case2 = j;
- j +=1 ;
- }
- }
- for(i = 2;i <3 ;i++)
- if ( ((case == 0) || (case2 == 1)) && (j == 0) ) j += 2;
- if ( ((case == 0) || (case2 == 2)) && (j == 0) ) j += 1;
- if ( ((case == 1) || (case2 == 0)) && (j == 0) ) j += 2;
- if ( ((case == 2) || (case2 == 0)) && (j == 0) ) j += 1;
- for(j = 0; j< 3 ;j++) {
- if (array2[i] == array1[j]) {
- sum += 1;
- }
- if ( ((case == 0) || (case2 == 2)) && (j == 1) ) j += 2;
- if ( ((case == 2) || (case2 == 0)) && (j == 1) ) j += 2;
- if ( ((case == 1) || (case2 == 2)) && (j == 0) ) j += 3;
- if ( ((case == 1) || (case2 == 2)) && (j == 0) ) j += 3;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement