Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // James Li
- // Comp1911 assignment 1
- // Tim Tam Game
- // FUNCTION DEFINITONS
- #include<stdio.h>
- #include<math.h>
- #include<ctype.h>
- #define N_NUMBERS 6
- int match(int num[N_NUMBERS]);
- // MAIN FUNCTION
- int num[N_NUMBERS];
- int main(void){
- // VARIABLES
- // EXECUTION OF MAIN FUNCTION
- // PLAYER ENTERS 6 NUMBERS
- // STORED IN AN ARRAY
- // NUMBERS BETWEEN 0-9 AND NON CHARACTER
- int num[N_NUMBERS];
- int count = 0;
- while (count < N_NUMBERS){
- scanf("%d", &num[count]);
- if (count > 0 && num[count-1] > num[count]){
- printf("Invalid input: 6 integers 1..9 in sorted order must be supplied. \n");
- break;
- }
- if(num[count] >= 1 && num[count] <=9){
- count = count + 1;
- } else {
- printf("Invalid input: 6 integers 1..9 in sorted order must be supplied. \n");
- break;
- }
- }
- //TOTAL
- int totalMain = 0;
- totalMain = num[0] + num[1] + num[2] + num[3] + num[4] + num[5];
- 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);
- //MATCHES
- int matchMain = 0;
- int a = 0;
- matchMain = match(num);
- printf("Rule MATCH(%d) - score %d\n", num[a], matchMain);
- //printf("Rule %d(%s) - score %d.\n", rule, str, max);
- //array
- // TELLS IF NUMBERS ARE IN NON-DECENDING ORDER - HOW TO PUT IT IN THE LOOP?
- // PRINTING OF FUNCTIONS
- //TO BE TAKEN OUT - ONLY PRINTING ARRAY
- printf("%d ", num[0]);
- printf("%d ", num[1]);
- printf("%d ", num[2]);
- printf("%d ", num[3]);
- printf("%d ", num[4]);
- printf("%d \n", num[5]);
- return 0;
- }
- // NUMBERS SORTED INTO A B C D E F BASED OFF NUMBERING
- // DONT KNOW HOW
- // NUMBERS ARE SORTED INTO THE NECESSAARY RULE
- // COMBINED WITH BELOW?
- // PRINTS WHICH RULE GIVES THE MOST VALUE - AND VALUE
- // IF STATEMENTS?
- // FUNCTION DESCRIPTIONS
- //MATCH
- int match(int num[N_NUMBERS]){
- int a = 0;
- int max = 0;
- int rule = 0;
- int MATCH_2 = 0;
- int MATCH_3 = 0;
- int MATCH_4 = 0;
- int MATCH_5 = 0;
- int MATCH_6 = 0;
- while(a < 5){
- if(num[a] == num[a+1]){
- if(max < (2*num[a] + 19)){
- rule = MATCH_2;
- max = (2 * num[a]) + 19;
- }
- if(a < 4 && num[a] == num[a+2]){
- rule = MATCH_3;
- max = (3 * num[a]) + 21;
- if(a < 3 && num[a] == num[a+3]){
- rule = MATCH_4;
- max = (4 * num[a]) + 23;
- if(a < 2 && num[a] == num[a+4]){
- rule = MATCH_5;
- max = (5 * num[a]) + 25;
- if(a < 1 && num[a] == num[a+5]){
- rule = MATCH_6;
- max = (6 * num[a]) + 27;
- }
- }
- }
- }
- }
- a = a +1;
- }
- return max;
- }
- // QUESTIONS TO ASK
- // 1) HOW FO YOU PUT THE NON-DECENDING ORDER INTO THE LOOP?
- // 2) HOW DO YOU END A PROGRAM IN THE WHILE LOOPS? 0 1 2 3 4 5
- // 2) HOW DO YOU GET THE VALUE OF Xa, AND HOW DO YOU GET THE HIGHEST VALUE?
- // 3) HOW DO YOU COMPARE FUNCTIONS AND GET THE HIGHEST ONE?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement