Tic-Tac-Toe

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2004
Posts: 40
Reputation: cybergirl is an unknown quantity at this point 
Solved Threads: 0
cybergirl's Avatar
cybergirl cybergirl is offline Offline
Light Poster

Re: We only give homework help to those who show effort

 
0
  #1
Apr 23rd, 2004
Hey guys,
I'm new here. And I was wondering if you could help me with a question i have. You see i have to write a C++ program that plays the game of tic-tac-toe. And the class contains as private data a 3-by-3 double subscripted array of integers. And i have to allow 2 players to use it. You see my problem is that i don't know how to make the 2 players access the array. Maybe you give me an example or some kind of advice so i have a better idea on how to do it.
Hey,
Do you know any good books that teach C++ for beginners?

Please, help me =)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Tic-Tac-Toe

 
0
  #2
Apr 23rd, 2004
Try the C++ primer plus ---by Stephen Prata.
It's ideal for beginners.
It's not me who says it. Look at the reviews in amazon.com on this book. It's really quite a hit.
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 307
Reputation: big_k105 is an unknown quantity at this point 
Solved Threads: 2
Team Colleague
big_k105's Avatar
big_k105 big_k105 is offline Offline
PFO Founder

Re: Tic-Tac-Toe

 
0
  #3
Apr 23rd, 2004
well im not sure how to help your problem but for recommending a book. i always recommend O'Reilly books, they seem to have some of the best books out there for programming and computers in general O'Reilly's Website and then here is the link to there c/c++ section http://cprog.oreilly.com/
good luck on getting your problem fixed im sure someone here will beable to help out shortly
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 40
Reputation: cybergirl is an unknown quantity at this point 
Solved Threads: 0
cybergirl's Avatar
cybergirl cybergirl is offline Offline
Light Poster

Re: Tic-Tac-Toe

 
0
  #4
Apr 23rd, 2004
Thank you guys!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Tic-Tac-Toe

 
0
  #5
Apr 24th, 2004
Here is an example of Tic-Tac-Toe.

But here u play against the computer.
See if it is of any help. It's an exapmle taken from herbert Schield's book on turbo C/C++--the complete reference.
Take care...
Attached Files
File Type: c TIC.C (2.0 KB, 862 views)
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 40
Reputation: cybergirl is an unknown quantity at this point 
Solved Threads: 0
cybergirl's Avatar
cybergirl cybergirl is offline Offline
Light Poster

Re: Tic-Tac-Toe

 
0
  #6
Apr 26th, 2004
is that example in C or C++?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 40
Reputation: cybergirl is an unknown quantity at this point 
Solved Threads: 0
cybergirl's Avatar
cybergirl cybergirl is offline Offline
Light Poster

Re: Tic-Tac-Toe

 
0
  #7
Apr 26th, 2004
what is "scanf"?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Tic-Tac-Toe

 
0
  #8
Apr 27th, 2004
the example is for C. But it will work for C++ as well.
Consider scanf() as equivalent of cin. scanf is used in C. C doesnt support cin. So u have to depend on scanf(). But not to worry; bcoz c++ can handle scanf() as well.
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 40
Reputation: cybergirl is an unknown quantity at this point 
Solved Threads: 0
cybergirl's Avatar
cybergirl cybergirl is offline Offline
Light Poster

Re: Tic-Tac-Toe

 
0
  #9
Apr 27th, 2004
Thank you,
if you were using cin, how would you write

int x,y;
printf("Enter coordinates for your X: ");
scanf("%d%d",&x,&y);

I think
printf is cout right?
so this will look in C++ like:

int x,y;
cout<<"Enter coordinates for your X: "<<endl;
cin>> ?? (This part i don't know, what are the % for?, &x and &y are pointers right?)

i don't know C.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: Tic-Tac-Toe

 
0
  #10
Apr 28th, 2004
Hello,

I do not claim to be an expert on C++.

scanf(%d%d,&x,&y) means it is looking for decimal integer. So, %d%d means "here come 2 decimal integers, and they are called variables x and y" The & symbol is the address operator of the variable. C is more cryptic than C++, but I think you will like it better than FORTRAN.

I think you can write the code:

// Let's declare and initialize the values
int x = 0, y = 0;

// User interaction to gather X and Y
// Put me in a loop though for error checking
cout << "Enter coordinates for your X: ";
cin >> x >> y;


If I were you, I would put these in loops to ensure error checking... what happens if someone tried to enter in -3, 7? Your code would probably fail.

Enjoy.

Christian
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC