Turbo C/C++ and other junk compilers help, discussions and queries here

aneesh kalra

Mclaren F1 Long tail
c++

Code:
while(i<3){
if(tc[i]==c,c,c)
flag=1;
Here i have referred to c as a char variable which is checked whether it contains another char variable p1 or p2 which hold the symbols of the two players in this game respectively.However c++ shows syntax error when I declare c as a char variable.how can i execute this piece of code.Actually it saves me the hassle of writing two seperate check functions for player 1 and player 2 .
Here is the complete code for my tic tac toe game .
Code:
//Program to run game tic toe
#include<iostream.h>
#include<conio.h>
char player1,player2;
int i=0,j=0,x=0,y=0;
char tc[3][3];
char p1,p2;
int flag=0;
void display(char )
{
for(;i<3;i++)
{
for(;j<3;j++)
cout<<tc[i][j];
}}
void check(char ,char )
{
while(i<3){
if(tc[i]==c,c,c)
flag=1;
}
while(j<3){
if(tc[j]==c,c,c)
flag=1;
}
while(i<j){
if(tc[i][j]==c,c,c)
flag=1;
}
while(i==j){
if(tc[i][j]==c,c,c)
flag=1;
}
if(flag==1){
if(c==p1){
cout<<player1<<"\t has won the game";
}
if(c==p2){
cout<<player2<<"\t has won the game";
}}}
void pos(int i,int j,char c)
{
tc[i][j]=c;
if(i>3,j>3,tc[i][j]!='\0')
cout<<"\n Invalid choice";
}
void initialize(char )
{
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
tc[i][j]='A';
}}
void main(){
cout<<"Welcome to the world of tic toe gaming"<<"\n  Program design and compilation by Aneesh";
cout<<"\n Please enter your names player 1 and player2 in that order";
cin>>player1>>player2;
cout<<"\n"<<player1<<"\t please enter you symbol of choice ";
cin>>p1;
cout<<"\n"<<player2<<"\t please enter your symbol of choice ";
cin>>p2;
while(flag!=1)
cout<<"\n"<< player1<<"\t please specify the position in terms of x and y where you want to place your symbol alongiwth it;ie; your symbo";
cin>>x>>y;
display(tc[3][3]);
pos(x,y,p1);
check(p1, tc[3][3]);
cout<<"\n"<<player2<<"\t please  specify the position in terms of x and y where you want to place your symbol alongwith it ;i.e;your symbol";
cin>>x>>y;
display( tc[3][3]);
pos(x,y,p2);
check(p2,tc[3][3]);
cout<<"\n Thank you for playing tic toe with us";
getch();
}
 

n2casey

Super Hero - Super Powers
Re: c++

As I think, multiple conditions in if() r give by using && or || operator.

&& is for condition of AND, and || is for condition of OR
e.g.
if (x>3 && y<7) means, if x greater than 3 and y less than 7

while
if (x>3 || y<7) means, if x greater than 3 or y less than 7
 

aneesh kalra

Mclaren F1 Long tail
Re: c++

actually the problem here is the variable within variable thing.I was asking whether this can be done or not.
 

mediator

Technomancer
Re: c++

I think there's a syntax error in this code!

There r many problems that I can see
1. One is as pointed my @n2casey (syntax error)
2. while is a loop. You have not put any increment in it!
while(j<3){
if(tc[j]==c,c,c)
flag=1;
This wud mean "if (tc[0]==c)", checking infinite times as j is equal to zero always (no increment).

3. Many Incorrect bracket's pairings.

aneesh_kalra said:
actually the problem here is the variable within variable thing.I was asking whether this can be done or not.
Variable within variable?? Means?
 

aneesh kalra

Mclaren F1 Long tail
Re: c++

The problem that I have stated about which I was confused was whether the aray could be checked for the variable fro within it;i.e; if i can check whether c has the value of p1;ie; player 1's symbol.Would using a reference variable be helpful.
.Can you please be more specific I understood the while thing missed it out but as far I know the brackets were correct.Your valuable guidance in the same will be higly appreciated.
 
Last edited:

mediator

Technomancer
Re: c++

Ah yes brackets r correct => my fault!

As for ur problem I'm still not clear what exactly u wanna ask. Neways an array stores values not variables!
 

n2casey

Super Hero - Super Powers
Re: c++

Yes, just take a look at what mediator & I have told u. Made those corrections & plz tell clearly what u want.
 

coolboy_n

Broken In
Re: c++

hi everyone,
using 'if(tc[j]==c,c,c)' is perfectly acceptable..

it'll be equivalent to if(tc[j]==c)

also...using a char variable will give u an error here....try using the ascii codes for those characters and put them into individual elements of the array..when u need the character-equivalents ..simply type-cast them.
I hope this'll do..!!
 

n2casey

Super Hero - Super Powers
Re: c++

@ coolboy_n

It's acceptable but not work like that. Just run this prog & u will come to know that.
Code:
#include<iostream.h>
void main()
{
char c0, c1='d', c2='f', c3='g';
cout<<"Press key"<<endl;
cin>>c0;
if(c0==c1,c2,c3)
cout<<"Good : "<<c0<<endl;
else
cout<<"Bad : "<<c0<<endl;
}
& here is the output

*img58.imageshack.us/img58/4228/44886068ab7.jpg
*img58.imageshack.us/img58/630/55770532po5.jpg

coz the condition if() will always b true.
 

aneesh kalra

Mclaren F1 Long tail
Re: c++

thanks for solving my query as here we are checking whether the array contains c1 ,c2 and c3 and not the charcter contained in c1.
Can it be done like this where cis an array
for(i=0;c!='\0';i++)
if(c=='c')
 

mediator

Technomancer
Re: c++

aneesh kalra said:
thanks for solving my query as here we are checking whether the array contains c1 ,c2 and c3 and not the charcter contained in c1.
Can it be done like this where c is an array
for(i=0;c!='\0';i++)
if(c=='c')

That wud mean c[1] to c[3] are being checked for value "c". If the array contains "values" c1,c2,c3 it wud return false when being checked for "c".

If u wanna check for a variable, then u shud check for its value. If u wanna compare array value, thenu shud check for its position and the value at that position. Checking array for "variable" cannot be done AFAIK coz variables contains values and array is a kind of variable!
 

speedyguy

Cyborg Agent
Turbo C/C++ graphics distorted

prgms r all running fine except wen i use graphics.h n use initgraph d output screen comes distorted....is thr any graphics driver issue....cuz othr graphics suckin appl r running absolutely fine....

cn i use any other compiler if no soln 2 dis...if yes any downloads available....
ps: i cant afford 2 use diff commands in case of compiler change..

waiting fr resp....urgently needed....hv grphcs pgming this semester fr project

thanx...

Enjoy~!
 

Kl@w-24

Slideshow Bob
Re: Turbo C/C++ graphics distorted

Could u plz paste the graphics initialization code dat u r using in ur program?
 

speedyguy

Cyborg Agent
Re: Turbo C/C++ graphics distorted

none of d graphic related commands execute thr....one f samples pasting here...

#include<iostream.h>
#include<conio.h>
#include<graphics.h>

void main()
{
int i,dx,dy,xa,ya,xb,yb,stp;
int gd=DETECT,gm;
float xincr,yincr,x,y;
initgraph(&gd,&gm,"");
clrscr();
cout<<"\n\tEnter starting co-ordinate-(x,y) ";
cin>>xa>>ya;
cout<<"\n\tEnter ending co-ordinate-(x,y) ";
cin>>xb>>yb;
dx=xa-xb;
dy=ya-yb;
if (dx>dy)
stp=dx;
else
stp=dy;
x=xa;
y=ya;
xincr=dx/stp;
yincr=dy/stp;
putpixel(x,y,4);
for (i=1;i<=stp;i++)
{
x=x+xincr;
y=y+yincr;
putpixel(x,y,4);
}
getch();
}


Enjoy~!
 

Kl@w-24

Slideshow Bob
Re: Turbo C/C++ graphics distorted

U need to provide the path to the gfx driver within " and " in:
Code:
initgraph(&gd,&gm,"");

Like this:
Code:
initgraph(&gd,&gm,"c:\\progra~1\\tc\\bgi");

Replace the path to the BGI folder with ur own, keeping the \\ intact. Try it.
 
Top Bottom