Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

Students also viewed these Databases questions