d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Changing C++ Code To Basic C > Needing Help With Tic Tac Toe
12Next
Add Reply New Topic New Poll
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 12 2013 02:21pm
I have my c++ program I made however teacher is requiring us to transfer this over to a 2 dimensional array tic tac toe in BASIC c PROGRAMMING code



Code
#include <iostream>
using namespace std;
void ShowTable(char [][3]);
void ResetTable(char[] [3]);
char Marker[][3]={'1','2','3','4','5','6','7','8','9'};
int main(void)
{
   char player_symbol = 'X';
   char player_turn = '1';
   char player_move;
   char play_again = 'Y';
   int R,C,times_played = 0; // just for FOR Loop

   ShowTable(Marker);

   do{


       cout << "Player No." << player_turn << " turn" << endl;

       cin >> player_move;

       for ( R = 0; R<3; R++)

       {

           for(C = 0; C<3; C++)

           {

               if(Marker[R][C] == player_move)

               {

                   Marker[R][C] = player_symbol;

               }

           }

       }



       for (R=0; R<3; R++)

       {

           if((Marker[R][0] == Marker[R][1] && Marker[R][1] == Marker[R][2]) || (Marker[0][R] == Marker[1][R]&& Marker[1][R] == Marker[2][R]))

           {

               ShowTable(Marker);

               cout << "Player No." << player_turn << " wins\nCongratulations\n" << endl;

               cout << "Do you wnat to player again\nEnter Y for yes ->" << endl;

               cin >> play_again;

               if(play_again == 'Y' || play_again == 'y')

               {

                   ResetTable(Marker);

                   play_again = 'Y';

                   player_turn = '2';

                   times_played = 0;

               }

           }

       }

       

       if((Marker[0][0] == Marker[1][1] && Marker[1][1] == Marker[2][2]) || (Marker[0][2] == Marker[1][1]&& Marker[1][1] == Marker[2][0]))

       {

           ShowTable(Marker);

           cout << "Player No." << player_turn << " wins\nCongratulations" << endl;

           cout << "Do you wnat to player again\nEnter Y for yes ->" << endl;

           cin >> play_again;

           if(play_again == 'Y' || play_again == 'y')

           {

               ResetTable(Marker);

               play_again = 'Y';

               player_turn = '2';

               times_played = 0;

           }

       }



       if( play_again == 'Y')

       {

           if(player_turn == '1')

           {

               player_turn = '2';

               player_symbol = 'O';

               ShowTable(Marker);

           }

           else

           {

               player_turn = '1';

               player_symbol = 'X';

               ShowTable(Marker);

           }

       }

       times_played++;

       if(times_played == 9)

       {

           cout << "There's no winner\n\nDo you want to play again?\nEnter Y for yes->\n";

           cin >> play_again;

           if(play_again == 'Y' || play_again == 'y')

           {

               ResetTable(Marker);

               play_again = 'Y';

               player_turn = '1';

               times_played = 0;

               ShowTable(Marker);

           }

       }



   }while(play_again == 'Y');



}



void ShowTable(char M[][3])

{

   int i,j;

   for(i=0;i<3;i++)

   {

       cout << "|  ";

       for(j=0;j<3;j++)

       {

           cout << M[i][j] << "  |  ";

       }

       cout << endl << endl;

   }

}



void ResetTable(char M[][3])

{

   char cChar = '1';

   int R,C;

   for(R=0; R<3; R++)

   {

       for(C=0; C<3; C++)

       {

           M[R][C] = cChar;

           cChar++;

       }

   }

}
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 12 2013 06:13pm
if you're capable of doing this in C++, can you explain why you can't do it in C?
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 19 2013 02:13pm
that is not an answer
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 19 2013 02:27pm
Quote (carteblanche @ Feb 12 2013 04:13pm)
if you're capable of doing this in C++, can you explain why you can't do it in C?


It's probably not his code

E/ if this was your code I guarantee you'd be able to convert it with ease. There's not much in this code that's needs to be changed in order to be C code

This post was edited by SelfTaught on Feb 19 2013 02:29pm
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 19 2013 03:17pm
Quote (SelfTaught @ Feb 19 2013 03:27pm)
It's probably not his code

E/ if this was your code I guarantee you'd be able to convert it with ease. There's not much in this code that's needs to be changed in order to be C code


the only thing you've done on my questions is bitch and call me a liar or call me stupid
iostream.h can be implemented into C but not all of it
I am more accustomed to C++ and java but never used C and dont ever plan on implementing C into any programs
so why dont you stfu and stop comming on my fucking topics YOUR NOT WANTED!
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 19 2013 03:33pm
Quote (Xarai @ Feb 19 2013 05:17pm)
the only thing you've done on my questions is bitch and call me a liar or call me stupid
iostream.h can be implemented into C but not all of it
I am more accustomed to C++ and java but never used C and dont ever plan on implementing C into any programs
so why dont you stfu and stop comming on my fucking topics YOUR NOT WANTED!


all your posts are low quality and the questions you ask deserve the answers we give you.

i can see literally less then 5 changes that have to be made for this to compile to C. why dont you try compiling it as C and just read through the compile time error logs and fix them one by one.
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 19 2013 03:53pm
Quote (Xarai @ Feb 19 2013 01:17pm)
the only thing you've done on my questions is bitch and call me a liar or call me stupid
iostream.h can be implemented into C but not all of it
I am more accustomed to C++ and java but never used C and dont ever plan on implementing C into any programs
so why dont you stfu and stop comming on my fucking topics YOUR NOT WANTED!


When did I ever call you stupid lol? Oh ya that's right... Never.

And you think I'm calling you a "liar" because I said that this probably isn't your code. I said that because it just seems very hard to believe that you wrote this code and can't figure out how to change a few minor things to convert into compileable C code.

But like AbDuCt said. Your questions deserve the answers that are given. One of the reasons you get the responses we give you is because it doesn't seem like you put forth any effort or make an attempt to try and figure things out on your own first. It seems like you come in here post a wall of code and expect use to give you answers. I bet if you did a small amount of research you wouldn't have a problem figuring this out. Not only would that save you the flame but it would also save you some time.

The only person that is not wanted kiddo, is you.
Member
Posts: 4,024
Joined: Apr 1 2009
Gold: 64,464.00
Feb 21 2013 01:07am
Quote (Xarai @ Feb 19 2013 05:17pm)
the only thing you've done on my questions is bitch and call me a liar or call me stupid
iostream.h can be implemented into C but not all of it
I am more accustomed to C++ and java but never used C and dont ever plan on implementing C into any programs
so why dont you stfu and stop comming on my fucking topics YOUR NOT WANTED!


This post was uncalled for.. If you get flamed, you got flamed for a reason.

You are here to learn, so try to have some perspective.
Member
Posts: 29,305
Joined: Nov 12 2005
Gold: 710.00
Feb 21 2013 02:53am
nvm

This post was edited by Skamakaze on Feb 21 2013 03:05am
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Mar 12 2013 02:03pm
Quote (Twisted454 @ Feb 21 2013 02:07am)
This post was uncalled for.. If you get flamed, you got flamed for a reason.

You are here to learn, so try to have some perspective.


no that post WAS called for, selftaught has been flaming me, being unhelpful and downright rude to me so fuck him

however for those that need help with my code I managed to rewrite most of it back to C

Code
#include <stdio.h>
#include <stdlib.h>
void ShowTable(char [][3]);
void ResetTable(char[] [3]);
char Marker[][3]={'1', '2', '3', '4', '5', '6', '7', '8', '9'};
int main(void)
{
char player_symbol = 'X';
char player_turn = '1';
char player_move;
char play_again = 'Y';
int R,C,times_played = 0; // just for FOR Loop

ShowTable(Marker);
do{
                 printf("Player No. %c turn \n", player_turn);
                 scanf("%c", &player_move);
                 for ( R = 0; R<3; R++)
                 {
                     for(C = 0; C<3; C++)
                     {
                           if(Marker[R][C] == player_move)
                           {
                                           Marker[R][C] = player_symbol;
                           }
                     }
                 }
                 for (R=0; R<3; R++)
                 {
                     if((Marker[R][0] == Marker[R][1] && Marker[R][1] == Marker[R][2]) || (Marker[0][R] == Marker[1][R]&& Marker[1][R] == Marker[2][R]))
                     {
                         ShowTable(Marker);
                         printf("Player No. %c wins\nCongratulations\n\n", player_turn);
                         printf("Do you want to player again\nEnter Y for yes ->\n");
                         scanf("%c", &play_again);
                         if(play_again == 'Y' || play_again == 'y')
                         {
                             ResetTable(Marker);
                             play_again = 'Y';
                             player_turn = '2';
                             times_played = 0;
                         }
                     }
                 }                    
                 if((Marker[0][0] == Marker[1][1] && Marker[1][1] == Marker[2][2]) || (Marker[0][2] == Marker[1][1]&& Marker[1][1] == Marker[2][0]))
                 {
                     ShowTable(Marker);
                     printf("Player No. %c wins\nCongratulations\n", player_turn);
                     printf("Do you wnat to player again\nEnter Y for yes ->\n");
                     scanf("%c", &play_again);
                     if(play_again == 'Y' || play_again == 'y')
                     {
                         ResetTable(Marker);
                         play_again = 'Y';
                         player_turn = '2';
                         times_played = 0;
                     }
                 }
                 if( play_again == 'Y')
                 {
                             if(player_turn == '1')
                             {
                                            player_turn = '2';
                                            player_symbol = 'O';
                                            ShowTable(Marker);
                                            }
                                            else
                                            {
                                                player_turn = '1';
                                                player_symbol = 'X';
                                                ShowTable(Marker);
                                                }
                                                }
                                                times_played++;
                                                if(times_played == 9)
                                                {
                                                                printf("There's no winner\n\nDo you want to play again?\nEnter Y for yes->\n");
                                                                scanf("%c", &play_again);
                                                                if(play_again == 'Y' || play_again == 'y')
                                                                {
                                                                              ResetTable(Marker);
                                                                              play_again = 'Y';
                                                                              player_turn = '1';
                                                                              times_played = 0;
                                                                              ShowTable(Marker);
                                                                              }
                                                                              }
                                                                              }while(play_again == 'Y');
                                                                              }
                                                                             
                                                                              void ShowTable(char M[][3])
                                                                              {
                                                                                   int i,j;
                                                                                   for(i=0;i<3;i++)
                                                                                   {
                                                                                                   printf("| ");
                                                                                                   for(j=0;j<3;j++)
                                                                                                   {
                                                                                                                   printf("%c | ", M[i][j]);
                                                                                                                   }
                                                                                                                   printf("\n\n");
                                                                                                                   }
                                                                                                                   }
                                                                                                                   void ResetTable(char M[][3])
                                                                                                                   {
                                                                                                                        char cChar = '1';
                                                                                                                        int R,C;
                                                                                                                        for(R=0; R<3; R++)
                                                                                                                        {
                                                                                                                                 for(C=0; C<3; C++)
                                                                                                                                 {
                                                                                                                                          M[R][C] = cChar;
                                                                                                                                          cChar++;
                                                                                                                                                                                                                          system ("pause");
                                                                                                                                                                                                                              }
                                                                                                                                                                                                                              }
                                                                                                                                                                                                                              }
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll