943,794 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 57349
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 23rd, 2004
0

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

Expand Post »
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 =)
Similar Threads
Reputation Points: 15
Solved Threads: 0
Light Poster
cybergirl is offline Offline
40 posts
since Apr 2004
Apr 23rd, 2004
0

Re: Tic-Tac-Toe

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.
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Apr 23rd, 2004
0

Re: Tic-Tac-Toe

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
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Apr 23rd, 2004
0

Re: Tic-Tac-Toe

Thank you guys!!
Reputation Points: 15
Solved Threads: 0
Light Poster
cybergirl is offline Offline
40 posts
since Apr 2004
Apr 24th, 2004
0

Re: Tic-Tac-Toe

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, 1527 views)
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Apr 26th, 2004
0

Re: Tic-Tac-Toe

is that example in C or C++?
Reputation Points: 15
Solved Threads: 0
Light Poster
cybergirl is offline Offline
40 posts
since Apr 2004
Apr 26th, 2004
0

Re: Tic-Tac-Toe

what is "scanf"?
Reputation Points: 15
Solved Threads: 0
Light Poster
cybergirl is offline Offline
40 posts
since Apr 2004
Apr 27th, 2004
0

Re: Tic-Tac-Toe

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.
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Apr 27th, 2004
0

Re: Tic-Tac-Toe

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.
Reputation Points: 15
Solved Threads: 0
Light Poster
cybergirl is offline Offline
40 posts
since Apr 2004
Apr 28th, 2004
0

Re: Tic-Tac-Toe

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
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Convert this C# declaration to C++
Next Thread in C++ Forum Timeline: Char problem in C++ Calculator





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC