Hey Friends i am new here !!
Well i have a project in which i am required to make some good program out of the Tubo C book !!
Now i was thinking of a Tic Tac Game or a Mathematical equation calculation program !

I`ve seen some examples here in this forum but all are of heavy codings and strings !!

But i cannot use strings pointers in my programs !!

i need to make a project using functions,arrays and operators and loops !!

can a tic tac game be made using these or not !! and if not then what else can i make !!!

please all you professional programmers help this future programmer !

i need to make this with in a week !!

waiting for all of yours help !!

Thanks You
Rizrash

Specially whatever i make i should able to grasp it comletely in order to explain to the prgrammer !!

you must mean Turbo C++, not Turbo C. But I don't know why you can't code it in c++. If you expect to get that project done in a week then you will have to work a lot of hours each day -- not much time left for play.

Yes, you can write either program without strings. Very easily.

Specially whatever i make i should able to grasp it comletely in order to explain to the prgrammer !!

As you should with all programs you write...

well i`ve found one coding lemme show you all !!
but can any one help me out in writing the comments for this progrma !!

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int board[10] = {2,2,2,2,2,2,2,2,2,2};
int turn = 1,flag = 0;
int player,comp;
void menu();
void go(int n);
void start_game();
void check_draw();
void draw_board();
void player_first();
void put_X_O(char ch,int pos);

main()
{
 clrscr();
 _setcursortype(_NOCURSOR);
 menu();
 getch();
 return(0);
}
void menu()
{
 int choice;
 printf("\n--------MENU--------");
 printf("\n1 : Play with X");
 printf("\n2 : Play with O");
 printf("\n3 : Exit");
 printf("\nEnter your choice:>");
 scanf("%d",&choice);
 turn = 1;
 switch (choice)
 {
  case 1:
   player = 1;
   comp = 0;
   player_first();
   break;
  case 2:
   player = 0;
   comp = 1;
   start_game();
   break;
  case 3:
   exit(0);
  default:
   menu();
 }
}
int make2()
{
 if(board[5] == 2)
  return 5;
 if(board[2] == 2)
  return 2;
 if(board[4] == 2)
  return 4;
 if(board[6] == 2)
  return 6;
 if(board[8] == 2)
  return 8;
 return 0;
}
int make4()
{
 if(board[1] == 2)
  return 1;
 if(board[3] == 2)
  return 3;
 if(board[7] == 2)
  return 7;
 if(board[9] == 2)
  return 9;
 return 0;
}
int posswin(int p)
{
// p==1 then X   p==0  then  O
 int i;
 int check_val,pos;
 if(p == 1)
  check_val = 18;
 else
  check_val = 50;
 i = 1;
 while(i<=9)//row check
 {
  if(board[i] * board[i+1] * board[i+2] == check_val)
  {
   if(board[i] == 2)
    return i;
   if(board[i+1] == 2)
    return i+1;
   if(board[i+2] == 2)
    return i+2;
  }
  i+=3;
 }
 i = 1;
 while(i<=3)//column check
 {
  if(board[i] * board[i+3] * board[i+6] == check_val)
  {
   if(board[i] == 2)
    return i;
   if(board[i+3] == 2)
    return i+3;
   if(board[i+6] == 2)
    return i+6;
  }
  i++;
 }
 if(board[1] * board[5] * board[9] == check_val)
 {
  if(board[1] == 2)
   return 1;
  if(board[5] == 2)
   return 5;
  if(board[9] == 2)
   return 9;
 }
 if(board[3] * board[5] * board[7] == check_val)
 {
  if(board[3] == 2)
   return 3;
  if(board[5] == 2)
   return 5;
  if(board[7] == 2)
   return 7;
 }
 return 0;
}
void go(int n)
{
 if(turn % 2)
  board[n] = 3;
 else
  board[n] = 5;
 turn++;
}
void player_first()
{
 int pos;
 check_draw();
 draw_board();
 gotoxy(30,18);
 printf("Your Turn :> ");
 scanf("%d",&pos);
 if(board[pos] != 2)
  player_first();
 if(pos == posswin(player))
 {
  go(pos);
  draw_board();
  gotoxy(30,20);
  textcolor(128+RED);
  cprintf("Player Wins");
  getch();
  exit(0);
 }
 go(pos);
 draw_board();
 start_game();
}
void start_game()
{
 // p==1 then X   p==0  then  O
 if(posswin(comp))
 {
  go(posswin(comp));
  flag = 1;
 }
 else
 if(posswin(player))
  go(posswin(player));
 else
 if(make2())
  go(make2());
 else
  go(make4());
 draw_board();
 if(flag)
 {
  gotoxy(30,20);
  textcolor(128+RED);
  cprintf("Computer wins");
  getch();
 }
 else
  player_first();
}
void check_draw()
{
 if(turn > 9)
 {
  gotoxy(30,20);
  textcolor(128+RED);
  cprintf("Game Draw");
  getch();
  exit(0);
 }
}
void draw_board()
{
 int j;
 for(j=9;j<17;j++)
 {
  gotoxy(35,j);
  printf("|       |");
 }
 gotoxy(28,11);
 printf("-----------------------");
 gotoxy(28,14);
 printf("-----------------------");
 for(j=1;j<10;j++)
 {
  if(board[j] == 3)
   put_X_O('X',j);
  else
  if(board[j] == 5)
   put_X_O('O',j);
 }
}
void put_X_O(char ch,int pos)
{
 int m;
 int x = 31, y = 10;
 m = pos;
 if(m > 3)
 {
  while(m > 3)
  {
   y += 3;
   m -= 3;
  }
 }
 if(pos % 3 == 0)
  x += 16;
 else
 {
  pos %= 3;
  pos--;
  while(pos)
  {
   x+=8;
   pos--;
  }
 }
 gotoxy(x,y);
 printf("%c",ch);
}

Please someone help me out with appropriate comments !!

Member Avatar for iamthwee

If you wrote it yourself you can comment on it yourself. And get rid of that turbo c compiler and get something half decent.

Then maybe others can help.

well i`ve found one coding lemme show you all !!
but can any one help me out in writing the comments for this progrma !!
...

Please someone help me out with appropriate comments !!

OK, the program needs to be formatted better
Posting code without code tags helps make the code unreadable
Writing code without commenting it makes the program hard to understand and follow.

Since it sounds like you just found this on the web somewhere, you should continue looking for code that's commented, and formatted.

And get rid of that turbo c compiler and get something half decent.

That would make moving the cursor and drawing the game board very hard to do :p

Hey Friends i am new here !!
Well i have a project in which i am required to make some good program out of the Tubo C book !!
Now i was thinking of a Tic Tac Game or a Mathematical equation calculation program !

I've seen some examples here in this forum but all are of heavy codings and strings !!

#include<stdio.h>
#include<conio.h>

void Board();
void PlayerX();
void PlayerO();
void Player_win();
void check();
int win=0,wrong_X=0,wrong_O=0,chk=0;

char name_X[30];
char name_O[30];
int pos_for_X[3][3];
int pos_for_O[3][3];
int pos_marked[3][3];

void main()
{
    int i,ch,j;
    char ans;
/*  clrscr();
    printf("\n\t\t\t\tTIC TAC TOE");
    printf("\n\t\t\t\t");
    for(i=1;i<=11;i++)
    {
        delay(10000);
        printf("*");
    }*/
    do
    {
        clrscr();
        printf("\n\t\t\t\tTIC TAC TOE");
        printf("\n\t\t\t\t");
        for(i=1;i<=11;i++)
        {
            delay(10000);
            printf("*");
        }
        printf("\n1.Start The Game");
        printf("\n2.Quit The Game");
        printf("\nEnter your choice(1-2) : ");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                chk=0;
                win=0;
                for(i=1;i<=3;i++)
                {
                    for(j=1;j<=3;j++)
                    {
                        pos_for_X[i][j]=0;
                        pos_for_O[i][j]=0;
                        pos_marked[i][j]=0;
                    }
                }
                printf("\n\n");
                clrscr();
                printf("\nEnter the name of the player playing for \'X\': ");
                fflush(stdin);
                gets(name_X);
                printf("\nEnter the name of the player playing for \'O\': ");
                fflush(stdin);
                gets(name_O);
                Board();
                for(;;)
                {
                    if(win==1)
                        break;
                    check();
                    if(chk==9)
                    {
                        printf("\n\t\t\tMATCH DRAWS!!");
                        printf("\nPress any key....");
                        break;
                    }
                    else
                        chk=0;
                    printf("\nTURN FOR %s:",name_X);
                    PlayerX();
                    do
                    {
                        if(wrong_X!=1)
                            break;
                        wrong_X=0;
                        printf("\nTURN FOR %s:",name_X);
                        PlayerX();
                    }while(wrong_X==1);
                    check();
                    if(chk==9)
                    {
                        printf("\n\t\t\tMATCH DRAWS");
                        printf("\nPress any key....");
                        break;
                    }
                    else
                        chk=0;
                    printf("\nTURN FOR %s:",name_O);
                    PlayerO();
                    do
                    {
                        if(wrong_O!=1)
                            break;
                        wrong_O=0;
                        printf("\nTURN FOR %s:",name_O);
                        PlayerO();
                    }while(wrong_O==1);

                    }
                Board();
                if(win!=1)
                {
                    printf("\n\t\t\tMATCH DRAWS!!");
                    printf("\nPress any key.......");
                }
                getch();
                break;
            case 2:
                printf("\n\n\n\t\t\tThank You For Playing The Game.");
                printf("\n\t\t\t###############################");
                getch();
                exit(1);
                break;
        }
        printf("\nWant To Play(Y/N) ? ");
        fflush(stdin);
        scanf("%c",&ans);
    }while(ans=='y' || ans=='Y');
}


void Board()
{
    int i,j;
    clrscr();
    printf("\n\t\t\t\tTIC TAC TOE BOARD");
    printf("\n\t\t\t\t*****************");
    printf("\n\n\n");
    printf("\n\t\t\t    1\t      2\t        3");
    for(i=1;i<=3;i++)
    {
        printf("\n \t\t\t _____________________________");
        printf("\n \t\t\tº\t  º\t   º\t     º");
        printf("\n\t\t%d\t",i);
        for(j=1;j<=3;j++)
        {

            if(pos_for_X[i][j]==1)
            {
                printf("    X");
                printf("     ");
            }
            else if(pos_for_O[i][j]==1)
            {
                printf("    O");
                printf("     ");
            }
            else
            {
                printf("          ");
                continue;
            }
        }
        printf("\n\t\t\tº\t  º\t   º\t     º");
    }
    printf("\n\t\t\t------------------------------");
    Player_win();
}


void PlayerX()
{
    int row,col;
    if(win==1)
        return;
    printf("\nEnter the row no. : ");
    fflush(stdin);
    scanf("%d",&row);
    printf("Enter the column no. : ");
    fflush(stdin);
    scanf("%d",&col);
    if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
    {
        printf("\nWRONG POSITION!! Press any key.....");
        wrong_X=1;
        getch();
        Board();
    }
    else
    {
        pos_for_X[row][col]=1;
        pos_marked[row][col]=1;
        Board();
    }
}
void PlayerO()
{
    int row,col;
    if(win==1)
        return;
    printf("\nEnter the row no. : ");
    scanf("%d",&row);
    printf("Enter the column no. : ");
    scanf("%d",&col);
    if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
    {
        printf("\nWRONG POSITION!! Press any key....");
        wrong_O=1;
        getch();
        Board();
    }
    else
    {
        pos_for_O[row][col]=1;
        pos_marked[row][col]=1;
        Board();
    }
}
void Player_win()
{
    int i;
    for(i=1;i<=3;i++)
    {
        if(pos_for_X[i][1]==1 && pos_for_X[i][2]==1 && pos_for_X[i][3]==1)
        {
            win=1;
            printf("\n\nRESULT: %s wins!!",name_X);
            printf("\nPress any key............");
            return;
        }
    }
    for(i=1;i<=3;i++)
    {
        if(pos_for_X[1][i]==1 && pos_for_X[2][i]==1 && pos_for_X[3][i]==1)
        {
            win=1;
            printf("\n\nRESULT: %s wins!!",name_X);
            printf("\nPress any key............");
            return;
        }
    }
    if(pos_for_X[1][1]==1 && pos_for_X[2][2]==1 && pos_for_X[3][3]==1)
    {
        win=1;
        printf("\n\nRESULTL: %s wins!!",name_X);
        printf("\nPress any key......");
        return;
    }
    else if(pos_for_X[1][3]==1 && pos_for_X[2][2]==1 && 
pos_for_X[3][1]==1)
    {
            win=1;
        printf("\n\nRESULT: %s wins!!",name_X);
                printf("\nPress any key.....");
        return;
    }

        for(i=1;i<=3;i++)
    {
        if(pos_for_O[i][1]==1 && pos_for_O[i][2]==1 && pos_for_O[i][3]==1)
        {
            win=1;
            printf("\n\nRESULT: %s wins!!",name_O);
                        printf("\nPress any key.....");
            return;
        }
    }
    for(i=1;i<=3;i++)
    {
        if(pos_for_O[1][i]==1 && pos_for_O[2][i]==1 && pos_for_O[3][i]==1)
        {
            win=1;
            printf("\n\nRESULT: %s wins!!",name_O);
                        printf("\nPress any key.....");
            return;
        }
    }
    if(pos_for_O[1][1]==1 && pos_for_O[2][2]==1 && pos_for_O[3][3]==1)
    {
        win=1;
        printf("\n\nRESULT: %s wins!!",name_O);
        printf("\nPress any key.....");
        return;
    }
    else if(pos_for_O[1][3]==1 && pos_for_O[2][2]==1 && 
pos_for_O[3][1]==1)
    {
            win=1;
        printf("\n\nRESULT: %s wins!!",name_O);
                printf("\nPress any key.....");
        return;
    }
}
void check()
{
    int i,j;
    for(i=1;i<=3;i++)
    {
        for(j=1;j<=3;j++)
        {
            if(pos_marked[i][j]==1)
                chk++;
            else
                continue;
        }
    }
}
commented: No code tags -5

can i have favor? please give another example .. beside snake or tic tac toe plz...

How about a little calculator? Go to Wikipedia, and read up on RPN (Reverse Polish Notation), or Tower of Hanoi, or a game of Blackjack, or Battleship or a simple encryption/decryption program, or Conways Game of Life?

Whatever you choose, make it something that personally interests you. The guy who started this thread just found some code that did what he needed, and then didn't even know how to add comments to it -- how sad. You can't learn much like that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.