4 Replies - 22925 Views - Last Post: 27 March 2007 - 04:53 AM Rate Topic: -----

#1 skycloud  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 07

Declaration Terminated Incorrectly

Posted 27 March 2007 - 02:03 AM

The bit in bold is causing a "declaration terminated incorrectly" error message. I've tried moving the parentheses around a bit, but this just causes more errors. What exactly is the problem here? Any help greatly appreciated.


//A program that will run a game of Connect Four

#include<iostream.h> //Contains the input and output commands
#include<iomanip.h> //Declares the C++ streams input/output manipulators
#include<stdio.h> //Defines types and macros
#include<conio.h>

void main(); //Tells C++ that this is the start of a program
void gameinformation(); //holds information about the game
void game();
void menuone();
void menutwo();
void exitgame(); //enables the player to quit the game
void badinput();
void init();
void display();
void clrscr();//Indicates the start of a block of code
{
char option, choice;
char player one[10],player two[10]="playerone";="playertwo";//creating the two pleyers
char symbol='O';symbol='X'; //creating the symbols to be used in the game
}
do
{
cout<<endl<<endl;
cout<<setw(5)<<""<<"Menu"<<endl<<endl;//Menu from which the player can choose different options
cout<<setw(5)<<""<<"1: Enter data "<<endl<<endl; //Entering character onto grid
cout<<setw(5)<<""<<"2: Update data "<<endl<<endl; //Updating the grid
cout<<setw(5)<<""<<"3: View grid "<<endl<<endl; //Viewing the updated grid
cout<<setw(5)<<""<<"4: Continue "<<endl<<endl; //Continue with the current game
cout<<setw(5)<<""<<"5: Quit game "<<endl<<endl; //Quit the current game
cout<<setw(5)<<""<<"Enter option choice: "<<endl<<endl; //User enters option
cin>>option; //Input of option selected by user
cout<<endl<<endl;
cout<<endl<<endl; //Output of result of input

switch (option)
{
case '1':gameinformation();
break;
case '2':game();
break;
case '3':menuone();
break;
case '4':menutwo();
break;
case '5':exitgame();
break;
default:badinput();
}
{
while (option!='5');

void gameinformation();
}
clrscr();//Tells the program to clear the screen
cout<<"Please enter your name, player one";
cout<<"Please enter your name, player two";

void game()
{
game information();
}
void menuone();
{
}
void menutwo();
{
}
void exitgame();
{
cout<<setw(10)<<"Game is exiting"<<endl;
}
void badinput();
{
clrscr();
cout<<setw(10)<<"Sorry, that is not a valid option"<<endl;
cout<<setw(10)<<"Please choose an option - 1, 2, 3, 4 or 5"<<endl;
}
void init()
{
int row, col;
for(row=0;row<7;row++)
for(col=0;col<7;col++)
board [row][col] =' ';
}
void display()
{
int row, col;
do
{
cout<<setw(25)<<" "<<" ";
cout<<setw(10)<<"playerone<<":o"<<currentplayer"<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__|__|__|"<<endl;
cout<<setw(10)<<playertwo<<": X"<<symbol<<endl;
for(row=6;row>=0;row--)
{
cout<<setw(25)<<" "<<"| | | | | | | | "<<endl;
cout<<setw(25)<<" "<<"| "<<board[row][0]<<"| "<<board[row][1]
<<"| "<<board[row][2]<<"| "<<board[row][3]
<<"| "<<board[row][4]<<"| "<<board[row][5]
<<"| "<<board[row][6]<<"| "<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__| "<<endl;
cout<<setw(25)<<" "<<"| 1| 2| 3| 4| 5| 6| 7| "<<endl;

row=0;
cout<<"Enter the column within which you wish to play";//asks the player to choose a number corresponding to a column on the grid
cin>>col; //Tells the program to enter a symbol based o=n the choice of the player
col--;

if (board[row][col]==' ')
{
board[row][col]=symbol;
}
else if {board[row][col]!=" ");
{
do
{
row++;
}
while (board[row][col]!=" ");
}
board [row][col]=symbol;

if(current player =='1')
{
symbol='X';//This is one of the two symbols to be used in the game
current player='2';
}
else if (current player=='2');
{
symbol='0';
current plater='1';
}
while(win='F');
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Declaration Terminated Incorrectly

#2 mydnight  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-March 07

Re: Declaration Terminated Incorrectly

Posted 27 March 2007 - 02:12 AM

What compiler are you using? All the ones I have on hand a) don't have conio.h, and b) require main to be of type int, not void.
Was This Post Helpful? 0
  • +
  • -

#3 skycloud  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 07

Re: Declaration Terminated Incorrectly

Posted 27 March 2007 - 02:14 AM

View Postmydnight, on 27 Mar, 2007 - 02:12 AM, said:

What compiler are you using? All the ones I have on hand a) don't have conio.h, and B) require main to be of type int, not void.



Turbo C++
Was This Post Helpful? 0
  • +
  • -

#4 skycloud  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 07

Re: Declaration Terminated Incorrectly

Posted 27 March 2007 - 03:39 AM

I've changed it around a bit, but the error seems to have changed as well. The problem is now a "expression syntax in function display error".

//A program that will run a game of Connect Four

#include<iostream.h> //Contains the input and output commands
#include<iomanip.h> //Declares the C++ streams input/output manipulators
#include<stdio.h> //Defines types and macros
#include<conio.h>

//Tells C++ that this is the start of a program
void gameinformation(); //holds information about the game
void game();
void menutwo();
void exitgame(); //enables the player to quit the game
void badinput();
void init();
void display();

char board[7][7],currentplayer;
char playerone[10],playertwo[10];//creating the two pleyers
char symbol='O'; //creating the symbols to be used in the game
char win;

void main()
{
char option, choice;
do
{
cout<<endl<<endl;
cout<<setw(5)<<""<<"Menu"<<endl<<endl;//Menu from which the player can choose different options
cout<<setw(5)<<""<<"1: Enter data "<<endl<<endl; //Entering character onto grid
cout<<setw(5)<<""<<"2: Update data "<<endl<<endl; //Updating the grid
cout<<setw(5)<<""<<"3: View grid "<<endl<<endl; //Viewing the updated grid
cout<<setw(5)<<""<<"4: Continue "<<endl<<endl; //Continue with the current game
cout<<setw(5)<<""<<"5: Quit game "<<endl<<endl; //Quit the current game
cout<<setw(5)<<""<<"Enter option choice: "<<endl<<endl; //User enters option
cin>>option; //Input of option selected by user
cout<<endl<<endl;
cout<<endl<<endl; //Output of result of input

switch (option)
{
case '1':gameinformation();
break;
case '2':game();
break;
case '3':display();
break;
case '4':menutwo();
break;
case '5':exitgame();
break;
default:badinput();
}
}
while (option!='5');
}

void gameinformation()
{
clrscr();//Tells the program to clear the screen
cout<<"Please enter your name, player one";
cout<<"Please enter your name, player two";
}

void game()
{
gameinformation();
}


void menutwo()
{
}

void exitgame()
{
cout<<setw(10)<<"Game is exiting"<<endl;
}

void badinput()
{
clrscr();
cout<<setw(10)<<"Sorry, that is not a valid option"<<endl;
cout<<setw(10)<<"Please choose an option - 1, 2, 3, 4 or 5"<<endl;
}

void init()
{
int row, col;
for(row=0;row<7;row++)
for(col=0;col<7;col++)
board [row][col] =' ';
}

void display()
{
int row, col;
do
{
cout<<setw(25)<<" "<<" ";
cout<<setw(10)<<playerone<<":"<<symbol<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__|__|__|"<<endl;
cout<<setw(10)<<playertwo<<":"<<symbol<<endl;
for(row=6;row>=0;row--)
{
cout<<setw(25)<<" "<<"| | | | | | | | "<<endl;
<<" "<<"| "<<board[row][0]<<"| "<<board[row][1]
<<" "<<"| "<<board[row][2]<<"| "<<board[row][3]
<<" "<<"| "<<board[row][4]<<"| "<<board[row][5]
cout<<setw(25)<<" "<<"| "<<board[row][6]<<"| "<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__| "<<endl;
cout<<setw(25)<<" "<<"| 1| 2| 3| 4| 5| 6| 7| "<<endl;

row=0;
cout<<"Enter the column within which you wish to play";//asks the player to choose a number corresponding to a column on the grid
cin>>col; //Tells the program to enter a symbol based on the choice of the player
col--;

if (board[row][col]==' ')
{
board[row][col]=symbol;
}
else if (board[row][col]!=' ')
{
do
{
row++;
}
while (board[row][col]!=' ');
}
board [row][col]=symbol;

if(currentplayer =='1')
{
symbol='X';//This is one of the two symbols to be used in the game
currentplayer='2';
}
else if (currentplayer=='2');
{
symbol='0';
currentplayer='1';
}
}
}
while(win=='F');

}

This post has been edited by skycloud: 27 March 2007 - 03:41 AM

Was This Post Helpful? 0
  • +
  • -

#5 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 289
  • View blog
  • Posts: 1,898
  • Joined: 25-October 06

Re: Declaration Terminated Incorrectly

Posted 27 March 2007 - 04:53 AM

in display()

for(row=6;row>=0;row--)
{
cout<<setw(25)<<" "<<"| | | | | | | | "<<endl;		   <<<<< remove;
<<" "<<"| "<<board[row][0]<<"| "<<board[row][1]
<<" "<<"| "<<board[row][2]<<"| "<<board[row][3]
<<" "<<"| "<<board[row][4]<<"| "<<board[row][5]	  <<< add a;
cout<<setw(25)<<" "<<"| "<<board[row][6]<<"| "<<endl;
cout<<setw(25)<<" "<<"|__|__|__|__|__|__|__| "<<endl;
cout<<setw(25)<<" "<<"| 1| 2| 3| 4| 5| 6| 7| "<<endl;


you have a ; on the end of one line and need one on the end of another

It should then compile
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1