Hello everyone, i'm new to programming in C++ and i am trying to make tic-tac-toe with the basic knowledge i have. I have proceed this much. -
#include <iostream>
-
using namespace std;
-
main()
-
{
-
int a,b,c,d,f;
-
cout<<"1,1|1,2|1,3\n";
-
cout<<"___|___|___\n";
-
cout<<"2,1|2,2|2,3\n";
-
cout<<"___|___|__\n";
-
cout<<"3,1|3,2|3,3\n";
-
cout<<" | | \n";
-
-
system ("pause");
-
-
system ("cls");
-
-
cout<<" X | |\n";
-
cout<<"___|___|___\n";
-
cout<<" | |\n";
-
cout<<"___|___|__\n";
-
cout<<" | |\n";
-
cout<<" | | \n";
-
-
cout<<"Make Your Move";
-
cout<<"a";
-
cin>>a;
-
cout<<"b";
-
cin>>b;
-
-
-
if(a==2&&b==2)
-
{
-
-
}
-
-
else
-
{
-
if (a==2 && b!=2)
-
{
-
c=1;
-
d=3;
-
}
-
else
-
-
if (a!=3 && c!=1)
-
{
-
c=3;
-
d=1;
-
}
-
else
-
{
-
-
c=1;
-
d=3;
-
}
-
}
-
-
system ("cls");
-
-
-
-
-
-
}
-
The logic behind this coding is not understandable, as i haven't written any comments, but its perfectly alright. All i need now is a function or command which can set my cursor in the tic-tac-toe box above. Means its like that if user inputs the value (like 1,1 for top left box, 2,2 for middle one, like in the above figure) i'll calculate that vaue with some procedure and will store that in a,b. Now all i'm looking for is such type of function which could set the cursor on value of 'a' and 'b'. eg if user inputs 1,2, then the cursor should be automatically set to that position 1,2 and print O. something like this. i just want to save my coding space, don't want to make boxes again and again and print that value in it.
Any idea or hint plz?
3 1250
The TicTacToe (search also "Noughts and Crosses") issue has been tackled quite often here....
the simplest solution (and I know it isn't actually what you asked) would be to redraw your board after every move, that is , rather than try to change what is on the screen, just create a new board to show the current state of play.
Moving the cursor position is not standard c++. On linux, you can use ncurses. On windows, some sort of call to the windows API should do the trick. I would just re-draw the board.
Moving the cursor position is not standard c++. On linux, you can use ncurses. On windows, some sort of call to the windows API should do the trick. I would just re-draw the board.
But wouldn't redrawing the board would increase the length of my Programme? Actually i have to sumbit this assignment and i don't want it to look awful lengthy.
Maybe i have to try this one if i don't find any other way out.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Theron NightStar |
last post by:
I am trying to teach myself c++. This is the first program I have ever
written that might have an practical use to me. I rather proud of it since
like implied - I have no real knowledge of c++.
...
|
by: emanuela |
last post by:
Hi,
I've a little question about C language:
according to the pthread_create signature:
int pthread_create(pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine)(void*),
void...
|
by: subnet |
last post by:
What does the standard say about this:
#include <stdio.h>
void somefunc(int a, int b, int c)
{
printf("%d %d %d\n", a, b, c);
}
int main(void) {
int i = 5;
|
by: facicad |
last post by:
I would like to set topmost another prog. from my program.
Ex: I use AutoCAD, run my prog. from autocad. My prog. is topmost but went I
would like to pick some object in autocad, I set TopMost to...
|
by: × ×™×¨ |
last post by:
Hello,
I've already sent such a messege, hopping to be answered shortly this time.
I am practicing c/c++ programming using microsoft visual c++ express 2005
express edition. Anyway, unlike other...
|
by: erekose666 |
last post by:
I need to make a prog that will
1) Allow the user to select a make of car from a list of say 6 cars in an array I am assuming using get (I think)
2) Allow the user to select a predetermined trip...
|
by: erekose666 |
last post by:
I need a java prog to do the following:
Create class Date with the following capabilities:
a) Output the date in multiple formats, such as:
MM/DD/YYYY
June 14, 2005
DDD YYYY
b) Use...
|
by: Tool69 |
last post by:
Hi,
I've got the following hierarchy:
mainprog/
__init__.py
prog.py
utils/
__init__.py
myutils.py
others/
|
by: tvnaidu |
last post by:
I am running prog with GDB - throws SIG32, why?
@localhost config]# gdb prog
GNU gdb Red Hat Linux (5.3.90-0.20030710.40rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |