Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- typedef char * string;
- int main(int argc, const char* argv[]){
- int rolls;
- int dice_num;
- int r;
- int y;
- int i;
- int win = 0;
- int lose = 0;
- int green = 0;
- int red = 0;
- char *die;
- srand(time(NULL));
- string dice[6];
- dice[0] = "red";
- dice[1] = "yellow";
- dice[2] = "yellow";
- dice[3] = "green";
- dice[4] = "green";
- dice[5] = "green";
- if(argc < 2 ){
- printf("How many times do you want to roll?\n");
- scanf("%d", &rolls);
- printf("How many dice do you want to roll?\n");
- scanf("%d", &dice_num);
- }
- else{
- rolls = atoi(argv[1]);
- dice_num = atoi(argv[2]);
- }
- for (i=rolls;i > 0;i--){
- for (y=dice_num;y > 0;y--){
- r=rand()%6;
- die = dice[r];
- printf("%s,",die);
- if(die == "green"){
- green++;
- }
- else if(die == "red"){
- red++;
- }
- }
- //printf("green: %d\nred: %d\n",green,red);
- printf("\n");
- if( green == 0 && red > 0 ){
- lose++;
- }
- else{
- win++;
- }
- red=0;
- green=0;
- }
- printf("Wins: %d\nLoses: %d\n",win,lose);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement