Question: CAN YOU CONVERT THIS C CODE TO R PROGRAMMING #include #include void gamecounts(int ngames); void secondary_try(int last_total); int win = 0; int lose = 0;

CAN YOU CONVERT THIS C CODE TO R PROGRAMMING

#include #include

void gamecounts(int ngames); void secondary_try(int last_total);

int win = 0; int lose = 0; int end_arr[10000] = {0}; int index = 0;

int main() { srand(time(NULL)); int ngames = 1000; gamecounts(ngames); for (int i = 0; i < 30; i++) { printf("%d ", end_arr[i]); } }

void gamecounts(int ngames) { for (int i = 0; i < ngames; i++) { unsigned int dice_1 = (rand() % 6) + 1; unsigned int dice_2 = (rand() % 6) + 1; unsigned int total_dice = dice_1 + dice_2; if (total_dice == 7 || total_dice == 11) { end_arr[0]++; } else if (total_dice == 2 || total_dice == 3 || total_dice == 12) { end_arr[0]++; } else { secondary_try(total_dice); } } }

void secondary_try(int last_total) { int counter = 1; while (1) { unsigned int dice_1 = (rand() % 6) + 1; unsigned int dice_2 = (rand() % 6) + 1; unsigned int total_dice = dice_1 + dice_2; if (total_dice == 7) { end_arr[counter]++; break; } else if (total_dice == last_total) { end_arr[counter]++; break; } else { last_total = total_dice; counter++; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!