473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Just need a function for my prog

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.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. main()
  4. {
  5.     int a,b,c,d,f;
  6.     cout<<"1,1|1,2|1,3\n";
  7.     cout<<"___|___|___\n";
  8.     cout<<"2,1|2,2|2,3\n";
  9.     cout<<"___|___|__\n";
  10.     cout<<"3,1|3,2|3,3\n";
  11.     cout<<"   |   |  \n";
  12.  
  13.     system ("pause");
  14.  
  15.     system ("cls");
  16.  
  17.     cout<<" X |   |\n";
  18.     cout<<"___|___|___\n";
  19.     cout<<"   |   |\n";
  20.     cout<<"___|___|__\n";
  21.     cout<<"   |   |\n";
  22.     cout<<"   |   |  \n";
  23.  
  24.     cout<<"Make Your Move";
  25.     cout<<"a";
  26.     cin>>a;
  27.     cout<<"b";
  28.     cin>>b;
  29.  
  30.  
  31.     if(a==2&&b==2)
  32.     {
  33.  
  34.     }
  35.  
  36.     else 
  37.     {
  38.         if (a==2 && b!=2)
  39.         {
  40.             c=1;
  41.             d=3;
  42.         }
  43.         else 
  44.  
  45.             if (a!=3 && c!=1)
  46.         {
  47.             c=3;
  48.             d=1;
  49.         }
  50.         else 
  51.         {
  52.  
  53.             c=1;
  54.             d=3;
  55.         }
  56.     }
  57.  
  58.     system ("cls");
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
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?
Jan 4 '07 #1
3 1250
DeMan
1,806 1GB
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.
Jan 4 '07 #2
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.
Jan 4 '07 #3
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.
Jan 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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++. ...
5
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...
13
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;
2
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...
1
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...
0
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...
7
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...
2
by: Tool69 | last post by:
Hi, I've got the following hierarchy: mainprog/ __init__.py prog.py utils/ __init__.py myutils.py others/
8
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,...
0
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,...
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.