i have this kind of code:
---------------------------------------------------------------------
Code:
#include <stdio.h>
#include <stdlib.h>
void show_box(void);
char who_first(void);
unsigned int get_random_exponent(void);
unsigned int get_integer(int exp);
int get_sum(int a, int b);
int take_box(int input);
int player_move(void);
char box[9] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};
int exponent[9], n_integer[9], m_integer[9], score[2];
char answer, input, value;
int i, a, b;
int main(void)
{
int playerMove, c;
int score[2] = {0, 0};
printf("let's play tic-tac-toe\n\n");
printf("your score:%d\tcomputer's score:%d\n\n\n", score[0], score[1]);
show_box();
get_random_exponent();
for (i=0 ; i<9 ; i++)
n_integer[i] = get_integer(exponent[i]);
for(i=0 ; i<9 ; i++)
exponent[i] = 0;
get_random_exponent();
for (i=0 ; i<9 ; i++)
m_integer[i] = get_integer(exponent[i]);
for(i=0; i<9 ; i++)
{ printf("%c = %d + %d\n\n", box[i], n_integer[i], m_integer[i]);
}
for (i=0 ; i<9 ; i++)
box[i] = get_sum(n_integer[i], m_integer[i]);
printf("sums:\n");
for(i=0 ; i<9 ; i++)
printf("%d\n", box[i]);
who_first();
if (answer == 'y'||answer == 'Y')
{ player_move();
}
else if (answer == 'n'||answer == 'N')
{
box[4] = 'X';
/* computer will take the middle box */
}
else
{ printf("i guess that's a no.");
/* computer takes middle box */
}
scanf("%d", &answer);
getchar();
return 0;
}
void show_box (void)
{
printf("\t###################\n");
printf("\t# # # #\n");
printf("\t# %c # %c # %c #\n", box[0], box[1], box[2]);
printf("\t# # # #\n");
printf("\t###################\n");
printf("\t# # # #\tyou = X\n");
printf("\t# %c # %c # %c #\n", box[3], box[4], box[5]);
printf("\t# # # #\tcomputer = O\n");
printf("\t###################\n");
printf("\t# # # #\n");
printf("\t# %c # %c # %c #\n", box[6], box[7], box[8]);
printf("\t# # # #\n");
printf("\t###################\n\n");
}
char who_first(void)
{
printf("play first (y/n)? ");
scanf("%c", &answer);
return answer;
}
unsigned int get_random_exponent(void)
{
int a, b, i;
exponent[0] = rand() % 9;
for (i=1 ; i<9 ; i++)
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
for (b=0 ; b<i ; b++)
{ if (a == exponent[b])
{ do
{ a = rand() % 9;
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
} while (a == exponent[b]);
}
}
exponent[i] = a;
}
}
unsigned int get_integer(int exp)
{
int value = 1;
while (exp > 0)
{ value *= 2;
exp--;
}
return value;
}
int get_sum(int a, int b)
{
value = a + b;
return value;
}
int player_move(void)
{
printf("input the sum of the integers assigned in the square you want to take: ");
scanf("%d", &input);
for (i=0 ; i<9 ; i++)
{ if (input == box[i])
{ if (box[i] == 'X'||box[i] == 'O')
{ printf("that box is already taken.\n");
player_move();
box[i] = 'X';
}
}
else
{ printf("wrong sum. try again.\n");
player_move();
}
}
printf("you entered a wrong sum.");
player_move();
}
-----------------------------------------------------
these are my problems:
1. why are the list of "sums" not sums? some are even difference! how can i fix this problem?
2. this code is not yet complete. when the player inputs the sum of a box the letter in the box should be replaced with an 'X'. How can i do that?
i badly need your help guys. thanks.