daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // James Li
  2. // Comp1911 assignment 1
  3. // Tim Tam Game
  4.  
  5. // FUNCTION DEFINITONS
  6.  
  7. #include<stdio.h>
  8. #include<math.h>
  9. #include<ctype.h>
  10.  
  11. #define N_NUMBERS 6
  12.  
  13. int match(int num[N_NUMBERS]);
  14.  
  15. // MAIN FUNCTION
  16.  
  17. int num[N_NUMBERS];
  18.  
  19. int main(void){
  20.  
  21. // VARIABLES
  22.  
  23. // EXECUTION OF MAIN FUNCTION
  24.  
  25.     // PLAYER ENTERS 6 NUMBERS
  26.     // STORED IN AN ARRAY
  27.     // NUMBERS BETWEEN 0-9 AND NON CHARACTER
  28.        
  29.         int num[N_NUMBERS];
  30.         int count = 0;
  31.  
  32.  
  33.         while (count < N_NUMBERS){
  34.             scanf("%d", &num[count]);
  35.             if (count > 0 && num[count-1] > num[count]){
  36.                 printf("Invalid input: 6 integers 1..9 in sorted order must be supplied. \n");
  37.                 break;
  38.             }
  39.             if(num[count] >= 1 && num[count] <=9){
  40.                 count = count + 1;    
  41.             } else {
  42.                 printf("Invalid input: 6 integers 1..9 in sorted order must be supplied. \n");
  43.                 break;
  44.             }                                                    
  45.         }
  46.  
  47. //TOTAL
  48.     int totalMain = 0;
  49.     totalMain = num[0] + num[1] + num[2] + num[3] + num[4] + num[5];
  50.     printf("Rule total(%d,%d,%d,%d,%d,%d) - score %d.\n", num[0], num[1], num[2],    num[3], num[4], num[5], totalMain);
  51.  
  52. //MATCHES
  53.     int matchMain = 0;
  54.     int a = 0;
  55.     matchMain = match(num);
  56.     printf("Rule MATCH(%d) - score %d\n", num[a], matchMain);  
  57.  
  58.        
  59.  
  60.          
  61.     //printf("Rule %d(%s) - score %d.\n", rule, str, max);
  62.  
  63. //array
  64.  
  65.     // TELLS IF NUMBERS ARE IN NON-DECENDING ORDER - HOW TO PUT IT IN THE LOOP?
  66.        
  67. // PRINTING OF FUNCTIONS
  68.  
  69.  
  70.        
  71.     //TO BE TAKEN OUT - ONLY PRINTING ARRAY
  72.     printf("%d ", num[0]);
  73.     printf("%d ", num[1]);
  74.     printf("%d ", num[2]);
  75.     printf("%d ", num[3]);
  76.     printf("%d ", num[4]);
  77.     printf("%d \n", num[5]);
  78.  
  79. return 0;
  80. }
  81.  
  82.  
  83.     // NUMBERS SORTED INTO A B C D E F BASED OFF NUMBERING
  84.         // DONT KNOW HOW
  85.    
  86.     // NUMBERS ARE SORTED INTO THE NECESSAARY RULE
  87.         // COMBINED WITH BELOW?
  88.  
  89.     // PRINTS WHICH RULE GIVES THE MOST VALUE - AND VALUE
  90.         // IF STATEMENTS?
  91.  
  92.  
  93.  
  94. // FUNCTION DESCRIPTIONS
  95.  
  96. //MATCH
  97.  
  98. int match(int num[N_NUMBERS]){
  99.         int a = 0;
  100.         int max = 0;
  101.         int rule = 0;
  102.         int MATCH_2 = 0;
  103.         int MATCH_3 = 0;
  104.         int MATCH_4 = 0;
  105.         int MATCH_5 = 0;
  106.         int MATCH_6 = 0;
  107.     while(a < 5){
  108.         if(num[a] == num[a+1]){
  109.             if(max < (2*num[a] + 19)){
  110.                 rule = MATCH_2;
  111.                 max = (2 * num[a]) + 19;
  112.             }
  113.             if(a < 4 && num[a] == num[a+2]){
  114.                 rule = MATCH_3;          
  115.                 max = (3 * num[a]) + 21;
  116.                 if(a < 3 && num[a] == num[a+3]){
  117.                     rule = MATCH_4;
  118.                     max = (4 * num[a]) + 23;    
  119.                     if(a < 2 && num[a] == num[a+4]){
  120.                         rule = MATCH_5;
  121.                         max = (5 * num[a]) + 25;        
  122.                         if(a < 1 && num[a] == num[a+5]){
  123.                             rule = MATCH_6;
  124.                             max = (6 * num[a]) + 27;
  125.                         }
  126.                     }
  127.                 }
  128.             }
  129.         }  
  130.     a = a +1;
  131.     }
  132.     return max;
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. // QUESTIONS TO ASK
  140.     // 1) HOW FO YOU PUT THE NON-DECENDING ORDER INTO THE LOOP?
  141.     // 2) HOW DO YOU END A PROGRAM IN THE WHILE LOOPS? 0 1 2 3 4 5
  142.     // 2) HOW DO YOU GET THE VALUE OF Xa, AND HOW DO YOU GET THE HIGHEST VALUE?
  143.     // 3) HOW DO YOU COMPARE FUNCTIONS AND GET THE HIGHEST ONE?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top