Advertisement
Guest User

Untitled

a guest
May 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void TossDie(int *array){
  5.                  int i;
  6.                  for(i=0; i<6; i++){
  7.                          *(array+i)=rand()%7;
  8.                          }
  9.      }
  10.      
  11. void Score(int *array, int *score){
  12.               int i;
  13.               *score=0;
  14.               for(i=0; i<6; i++){
  15.                        *score+=*(array+i);
  16.                        }
  17.                        printf(" Score = %d\n", *score);
  18.     }
  19.    
  20. void HighScore(int *score, int players, char (*names)[20]){
  21.                    if(players==0) return;
  22.                    int highscore=0;
  23.                    int winnernumber;
  24.                    int i;
  25.                    printf("\nCounting the highest score\n");
  26.                    for(i=0; i<players; i++){
  27.                        if(*(score+i)>highscore){
  28.                                                 highscore=*(score+i);
  29.                                                 winnernumber=i;
  30.                                                 }
  31.                        }
  32.                        
  33.                    for(i=0; i<players; i++){
  34.                        if((*(score+i))==highscore){
  35.                                                 printf("And the winner is player: %s with highest score of %d !!!\n", *(names+i), highscore );
  36.                                                 }
  37.                        }
  38.                        
  39.                    
  40.      }
  41.    
  42. void PrintDie(int *array){
  43.                   int i;
  44.                   printf(" Threw ");
  45.                   for(i=0; i<6; i++){
  46.                        printf("%d  ", *(array+i));
  47.                          }
  48.                   printf("Which sums to");
  49.      }
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53.   int *array = (int*)malloc(sizeof(int)*6);
  54.    srand(time(0));
  55.    
  56.    printf("Enter number of players:");
  57.    int players;
  58.    scanf("%d", &players);
  59.    char names[players][20];
  60.    int scores[players];
  61.    int i;
  62.    printf("\n");
  63.    
  64.    for(i=0; i<players; i++){
  65.             printf("Enter name of player %d:", i+1);
  66.             scanf("%s", &names[i]);
  67.            }
  68.            printf("\n\n");
  69.    
  70.    for(i=0; i<players; i++){
  71.             printf("Player %s:\t", names[i]);
  72.             TossDie(array);
  73.             PrintDie(array);
  74.             Score(array, &scores[i]);
  75.            }        
  76.    
  77.    HighScore(scores, players, &names);      
  78.    
  79.    printf("\n\n");
  80.    free(array);
  81.    system("PAUSE");
  82.    return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement