I need to create a program that receives two numbers from the user (rows and columns) and then generates a board with arrows in random direction. In the middle of the board should be a diamond.
This is my code. It does not generate arrows and does not create diamond in the middle.
Code:#include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h> #include <time.h> #include <stdio.h> /* Function that generates the board */ int boardgame(int row, int column) { int i,j, board2[row][column],num; float r,c; srand(time(NULL)); r=row; c=column; for (i=0; i<row; i++) { for (j=0; j<column; j++) { if ((j==(c/2.0)) && (i==(r/2.0))) { board2[i][j]=35; } else if (((j-1)==(c/2.0)) && (i==(r/2.0))) { board2[i][j]=59; } else if ((j==(c/2.0)) && ((i-1)==(r/2.0))) { board2[i][j]=59; } else if (((j-1)==(c/2.0)) && ((i-1)==(r/2.0))) { board2[i][j]=35; } else { num=(10 + rand()% 4); board2[i][j]=num; } } } return (board2[row][column]); } int main() { int z,x,row,column, q1=1; int board[20][20]; /* Checks if the entered # of rows and columns is correct */ while (q1==1) { printf("Please enter the even # of rows (4,6,8,10,12,14,16,18,20):"); scanf("%d", &row); printf("Please enter the even # of columns (4,6,8,10,12,14,16,18,20):"); scanf("%d", &column); if ((row>20) || (row<4) || (column>20) || (column<4) || !(row%2==0) || !(column%2==0)) printf("Invalid Data\n"); else q1=0; } board[20][20]=boardgame(row,column); printf("\n\n\n"); /* Prints the board */ for (z=0; z<row; z++) { printf("%d", row-z); for (x=0; x<column; x++) { printf(" %c ", board[z][x]); } printf("\n\n"); } printf(" "); for (z=1; z<=column; z++) printf(" %d ", z); printf("\n\n\n"); system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks


