| | |
Tic-Tac-Toe
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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 =)
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 =)
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
good luck on getting your problem fixed im sure someone here will beable to help out shortly
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...
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...
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
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.
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)
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.
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.
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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
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
![]() |
Similar Threads
- Tic Tac Toe Homework (C++)
- Tic Tac toe help (C)
- Tic Tac Toe AI help, where to reset variables. (C++)
Other Threads in the C++ Forum
- Previous Thread: Help me please!!!!!!!!
- Next Thread: Visual studio C++ 2005
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






