[COLOR=#0000FF][FONT=Consolas]I am trying to add 2 functions to my program. one is displayMap which works ok , but the other is move which is aksing user which way he would like to move the x . i dont know how to pass value of row and col to this function and in the same time pass opt which is the letter which user will choose to move the X .
Code:
#include <stdio.h>
int displayMap(int, int);
void move();
int main(void)
{
int i, j, row, col;
char opt;
int mul;
do {
printf("\nPlease enter an X coordinate (a number between 1 and 10): \n");
scanf("%d", &col);
printf("Please enter an Y coordinate (a number between 1 and 10): \n");
scanf("%d", &row);
if (col > 10 || row > 10) {
printf("Numbers has to be between 1 and 10 \n");
}
} while (col > 10 || row > 10);
while (opt != 'x' && opt != 'X') {
mul = displayMap(col, row);
printf("\nDo you want to move the 'X'? \n");
printf("W - move up\n");
printf("S - move down\n");
printf("A - move left\n");
printf("D - move right\n");
printf("x - exit\n");
while ((opt = getchar()) != '\n' && opt != EOF);
scanf("%c", &opt);
move(opt);
}
}
int displayMap(col, row)
{
int i = 1, j = 1;
while (i <= 10) {
while (j <= 10) {
if (i == row && j == col) {
printf(" X ");
} else {
printf(" - ");
}
j++;
}
i++;
j = 1;
printf("\n");
}
}
void move(opt, mul)
{
int displayMap(col, row)
if (opt == 'W' || opt == 'w') {
row--;
if (row == 0) {
row = row + 10;
}
} else if (opt == 'S' || opt == 's') {
row++;
if (row == 11) {
row = row - 10;
}
} else if (opt == 'A' || opt == 'a') {
col--;
if (col == 0) {
col = col + 10;
}
} else if (opt == 'D' || opt == 'd') {
col++;
if (col == 11) {
col = col - 10;
}
} else if (opt == 'X' || opt == 'x') {
printf("Thank You for using my program Bye");
}
}