Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void TossDie(int *array){
- int i;
- for(i=0; i<6; i++){
- *(array+i)=rand()%7;
- }
- }
- void Score(int *array, int *score){
- int i;
- *score=0;
- for(i=0; i<6; i++){
- *score+=*(array+i);
- }
- printf(" Score = %d\n", *score);
- }
- void HighScore(int *score, int players, char (*names)[20]){
- if(players==0) return;
- int highscore=0;
- int winnernumber;
- int i;
- printf("\nCounting the highest score\n");
- for(i=0; i<players; i++){
- if(*(score+i)>highscore){
- highscore=*(score+i);
- winnernumber=i;
- }
- }
- for(i=0; i<players; i++){
- if((*(score+i))==highscore){
- printf("And the winner is player: %s with highest score of %d !!!\n", *(names+i), highscore );
- }
- }
- }
- void PrintDie(int *array){
- int i;
- printf(" Threw ");
- for(i=0; i<6; i++){
- printf("%d ", *(array+i));
- }
- printf("Which sums to");
- }
- int main(int argc, char *argv[])
- {
- int *array = (int*)malloc(sizeof(int)*6);
- srand(time(0));
- printf("Enter number of players:");
- int players;
- scanf("%d", &players);
- char names[players][20];
- int scores[players];
- int i;
- printf("\n");
- for(i=0; i<players; i++){
- printf("Enter name of player %d:", i+1);
- scanf("%s", &names[i]);
- }
- printf("\n\n");
- for(i=0; i<players; i++){
- printf("Player %s:\t", names[i]);
- TossDie(array);
- PrintDie(array);
- Score(array, &scores[i]);
- }
- HighScore(scores, players, &names);
- printf("\n\n");
- free(array);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement