There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware missing monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: syntax error - visual studio c++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Ghaleon's Avatar
Senior Member with 282 posts.
 
Join Date: Dec 2004
Experience: Beginner
08-Dec-2005, 01:47 AM #1
Solved: syntax error - visual studio c++
Hi All,
I'm taking a programing class and am very new to all of this; so bare wtih me if the following code is excessively sloppy. When I compile this it gives me

error C2059: syntax error : '}'

-it's pointing to the last bracket in the main function(clearly marked in comments, just scroll); does anybody know what's going on? Thanks for your time. Here's the code:



#include <iostream.h>
#include "wordBank.h"
#include <string.h>
#include "Gallows.h"
int drawWord (char x [21], char guess, int length);

void main ()

{
do
{
char x [21], guess, guessed[21];
wordBank y;
int z=0, hit, Misses=0, i=0, end=0;
static int turn=0;
y.readfile();
strcpy(x,y.getRandomWord());

Gallows g;

g.draw(Misses);

y.setWordLength(x);
int length=0;
length=y.getWordLength();

while (Misses<7)
{

cout<<endl<<"guess a letter\n";
end=drawWord(x, guess, length);
cout<<endl;
cin>>guess;

turn++;

hit=y.findLetter(guess, x);
g.setMisses(hit, x, guess);
Misses=g.getMisses();
g.draw(Misses);

cout<<"you have guessed: ";
int n=g.getNumGuessed();
g.setGuessed(guess);
int num=g.getNumGuessed();
for(i=0; i<num; i++)
{
cout<<g.getGuessed(i);
guessed[i]=g.getGuessed(i);


}

if (Misses==6)
{
cout<<"you loose\n";
end=1;
}

if (end==1)
{
cout<<"would you like to play again(0=no, 1=yes)?\n";
cin>>end;
}


}while(end!=1);

}
}//<********** it's pointing here***********

int drawWord(char x[21], char guess, int length)
{
static char display[21]="";
int win=0;

for (int i=0; x[i]!='\0'; i++)
{
if (guess==x[i])
{
display[i]=guess;
}

else if (guess!=x[i] && display[i]!='A'&& display[i]!='B'&& display[i]!='C'&& display[i]!='D'
&& display[i]!='E'&& display[i]!='F'&& display[i]!='G'&& display[i]!='H'
&& display[i]!='I'&& display[i]!='J'&& display[i]!='K'&& display[i]!='L'
&& display[i]!='M'&& display[i]!='N'&& display[i]!='O'&& display[i]!='P'
&& display[i]!='Q'&& display[i]!='R'&& display[i]!='S'&& display[i]!='T'
&& display[i]!='U'&& display[i]!='V'&& display[i]!='W'&& display[i]!='X'
&& display[i]!='Y' && display[i]!='Z' && display[i]!='a'&& display[i]!='b'
&& display[i]!='c'&& display[i]!='d'&& display[i]!='e'&& display[i]!='f'
&& display[i]!='g'&& display[i]!='h'&& display[i]!='i'&& display[i]!='j'
&& display[i]!='k'&& display[i]!='l'&& display[i]!='m'&& display[i]!='n'
&& display[i]!='o'&& display[i]!='p'&& display[i]!='q'&& display[i]!='r'
&& display[i]!='s'&& display[i]!='t'&& display[i]!='u'&& display[i]!='v'
&& display[i]!='w'&& display[i]!='x'&& display[i]!='y'&& display[i]!='z')



{
display[i]='-';
}

if(display[i]!='-')
{
win++;
cout<<"hits= "<<win<<endl;

cout<<"length= "<<length<<endl;

if (win==length)
{
return 1;
}
}

}

cout<<endl<<display;
return 0;
}
Ghaleon's Avatar
Senior Member with 282 posts.
 
Join Date: Dec 2004
Experience: Beginner
08-Dec-2005, 01:59 AM #2
never mind. I figured it out. the while loop should have been ended one bracket later. Thanks.
Mithrilhall's Avatar
Senior Member with 781 posts.
 
Join Date: Mar 2001
Location: AU Microscopii
Experience: Studying for my CCNA
08-Dec-2005, 02:05 AM #3
I'm assuming it's this line:

Code:
}//<********** it's pointing here***********
I've tried doing my best but I don't have a compiler installed and it's been a few years since I've taken my C++ class.

Code:
#include <iostream.h>
#include "wordBank.h"
#include <string.h>
#include "Gallows.h"
int drawWord (char x [21], char guess, int length);

void main ()
{
	do
	{
		char x [21], guess, guessed[21];
		wordBank y;
		int z=0, hit, Misses=0, i=0, end=0;
		static int turn=0;
		y.readfile();
		strcpy(x,y.getRandomWord());
		
		Gallows g;
		
		g.draw(Misses);
		
		y.setWordLength(x);
		int length=0;
		length=y.getWordLength();
		
		while (Misses<7)
		{
			cout<<endl<<"guess a letter\n";
			end=drawWord(x, guess, length);
			cout<<endl;
			cin>>guess;
			
			turn++;
			
			hit=y.findLetter(guess, x);
			g.setMisses(hit, x, guess);
			Misses=g.getMisses();
			g.draw(Misses);
			
			cout<<"you have guessed: ";
			int n=g.getNumGuessed();
			g.setGuessed(guess);
			int num=g.getNumGuessed();
			for(i=0; i<num; i++)
			{
				cout<<g.getGuessed(i);
				guessed[i]=g.getGuessed(i);
			}
			
			if (Misses==6)
			{
				cout<<"you loose\n";
				end=1;
			}
			
			if (end==1)
			{
				cout<<"would you like to play again(0=no, 1=yes)?\n";
				cin>>end;
			}	
		}
	while(end!=1);
	}
		
	int drawWord(char x[21], char guess, int length)
	{
	static char display[21]="";
	int win=0;
	
	for (int i=0; x[i]!='\0'; i++)
	{
		if (guess==x[i])
		{
			display[i]=guess;
		}
		else if (guess!=x[i] && display[i]!='A'&& display[i]!='B'&& display[i]!='C'&& display[i]!='D'
		&& display[i]!='E'&& display[i]!='F'&& display[i]!='G'&& display[i]!='H'
		&& display[i]!='I'&& display[i]!='J'&& display[i]!='K'&& display[i]!='L'
		&& display[i]!='M'&& display[i]!='N'&& display[i]!='O'&& display[i]!='P'
		&& display[i]!='Q'&& display[i]!='R'&& display[i]!='S'&& display[i]!='T'
		&& display[i]!='U'&& display[i]!='V'&& display[i]!='W'&& display[i]!='X'
		&& display[i]!='Y' && display[i]!='Z' && display[i]!='a'&& display[i]!='b'
		&& display[i]!='c'&& display[i]!='d'&& display[i]!='e'&& display[i]!='f'
		&& display[i]!='g'&& display[i]!='h'&& display[i]!='i'&& display[i]!='j'
		&& display[i]!='k'&& display[i]!='l'&& display[i]!='m'&& display[i]!='n'
		&& display[i]!='o'&& display[i]!='p'&& display[i]!='q'&& display[i]!='r'
		&& display[i]!='s'&& display[i]!='t'&& display[i]!='u'&& display[i]!='v'
		&& display[i]!='w'&& display[i]!='x'&& display[i]!='y'&& display[i]!='z')	
		{
			display[i]='-';
		}
	
		if(display[i]!='-')
		{
			win++;
			cout<<"hits= "<<win<<endl;
			
			cout<<"length= "<<length<<endl;
			
			if (win==length)
			{
				return 1;
			}
		}
	}
	
	cout<<endl<<display;
	return 0;
}
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:41 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.