Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Converting easy C++ Code to MATLAB code? How would I convert the following into MATLAB code? #include #include #include using namespace std; int main() {

Converting easy C++ Code to MATLAB code?

How would I convert the following into MATLAB code?

#include #include #include using namespace std;

int main() { srand(time(NULL)); int board[512][512] = {0};//Initializing to 0: default value int hits[20][2] = {0};//count hits on each numbers for each players int properHitsLeft[2]={20,20};//remaining distinct hits for each players int count=0, x, y, score, times; cout << "Dart game: round the world" << endl; /* Construction of the board*/ board[256][256] = 50;//Bull's eye /* Inner bull construction*/ board[255][255] = 25; board[255][256] = 25; board[255][257] = 25; board[256][255] = 25; board[256][257] = 25; board[257][255] = 25; board[257][256] = 25; board[257][257] = 25; for (score= 1; score<=20; score++) {// For score = 1 to 20 for (times= 0; times<20; times++) {//Fill board for 20 times x = rand()%512; y = rand()%512; if (board[x][y] == 0) { board[x][y] = score; } else { times--;//If already preoccupied by some other score-value, try again } } } /*Game starts*/ while (properHitsLeft[0]*properHitsLeft[1] != 0){ x = rand()%512; y = rand()%512; if (board[x][y] > 0 && board[x][y] < 21) { //If shot inside the board excluding bull's eye and outer bull if (hits[board[x][y]-1][count%2] == 0) { properHitsLeft[count%2]--; } hits[board[x][y]-1][count%2]++; } count++; } cout<< "Total darts thrown: "<< count <

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago