syntax error for another program.

This is a discussion on syntax error for another program. within the C++ Programming forums, part of the General Programming Boards category; I have never seen this error before, what is it and how can I fix it? Code: #include <iostream.h> #include ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    66

    syntax error for another program.

    I have never seen this error before, what is it and how can I fix it?

    Code:
     #include <iostream.h>
     #include    <conio.h>
    
     const max_length=10;
    
     class Stack
        {
           private:
    	  int stack[max_length];
    	  int top;
    
           public:
    	  Stack( );
    
    	  void pop( );
    	  void push( );
    	  void print_stack( );
    	  void show_working( );
        };
    
     void Stack::Stack( )
        {
           top=-1;
    
           for(int count=0;count<max_length;count++)
    	  stack[count]=0;
        }
    
     void Stack::push( )
        {
           int item;
    
           cout<<"\n\n\n\n\n\t Enter value to push onto Stack : ";
           cin>>item;
    
           if(top==(max_length-1))
    	  cout<<"\n\n\t ***  Error : Stack is full. \n"<<endl;
    
           else
    	  {
    	     top++;
    	     stack[top]=item;
    
    	     cout<<"\n\n\t *** "<<item<<" is pushed onto the Stack."<<endl;
    	  }
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::pop( )
        {
           if(top==-1)
    	  cout<<"\n\n\n\t ***  Error : Stack is empty. \n"<<endl;
    
           else
    	  {
    	     cout<<"\n\n\n\t *** "<<stack[top]<<" is poped from the Stack."<<endl;
    
    	     stack[top]=0;
    	     top--;
    	  }
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::print_stack( )
        {
           if(top!=-1)
    	  {
    	     cout<<"\n\n\n\n\n\t Values pushed onto Stack are : \n"<<endl;
    
    	     for(int count=0;count<=top;count++)
    		cout<<"\t Stack ["<<count<<"]  =  "<<stack[count]<<endl;
    	  }
    
           else
    	  cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl;
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::show_working( )
        {
           char Key=NULL;
           do
    	  {
    	     clrscr( );
    
    	     gotoxy(5,5);
    	     cout<<"Sequential Stack"<<endl;
    
    	     gotoxy(10,8);
    	     cout<<"Select one:"<<endl;
    
    	     gotoxy(15,10);
    	     cout<<"- Press \P\ to Push a value"<<endl;
    
    	     gotoxy(15,12);
    	     cout<<"- Press \O\ to Pop a value"<<endl;
    
    	     gotoxy(15,14);
    	     cout<<"- Press \S\ to Print the values"<<endl;
    
    	     gotoxy(15,16);
    	     cout<<"- Press \E\ to Exit"<<endl;
    
    	     Input:
    
    	     gotoxy(10,20);
    	     cout<<"                      ";
    
    	     gotoxy(10,20);
    	     cout<<"Enter your Choice : ";
    
    	     Key=getche( );
    
    	     if(int(Key)==27 || Key=='e' || Key=='E')
    		break;
    
    	     else if(Key=='p' || Key=='P')
    		push( );
    
    	     else if(Key=='o' || Key=='O')
    		pop( );
    
    	     else if(Key=='s' || Key=='S')
    		print_stack( );
    
    	     else
    		goto Input;
    	  }
           while(1);
        }
    
     int main( )
        {
           Stack obj;
    
           obj.show_working( );
    
           return 0;
        }

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Just having a brief look at your code, it appears you're missing a type specifier for the max_length variable.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    What error is that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    1. What is error?
    2. #include <iostream>
    3. conio.h is not standard
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Code:
    Info :stack hoskins v3.cpp: out of date with destination stack hoskins v3.obj
    Info :  stack hoskins v3.cpp: source date 11:23:25 AM 12/13/2006  destination date <unknown>
    Info :Compiling C:\Documents and Settings\labpc\Desktop\stack hoskins v3.cpp
    Error:  stack hoskins v3.cpp(23,6):Constructor cannot have a return type specification
    Warn :  stack hoskins v3.cpp(122,11):Conversion may lose significant digits

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    this is where I found out about conio.h

    http://www.digitalmars.com/rtl/conio.html

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    /*void*/ Stack::Stack( )
    getche returns int - you store it in char
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Do you have an example of the fix on that one?

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    declare your Key variable as int
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    thanks, the conversion error is gone. The other one is still there though.

  11. #11
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    remove the return type of the constructor
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    where is that?

    Code:
     #include <iostream.h>
     #include    <conio.h>
    
     const max_length=10;
    
     class Stack
        {
           private:
    	  int stack[max_length];
    	  int top;
    
           public:
    	  Stack( );
    
    	  void pop( );
    	  void push( );
    	  void print_stack( );
    	  void show_working( );
        };
    
     void Stack::Stack( )
        {
           top=-1;
    
           for(int count=0;count<max_length;count++)
    	  stack[count]=0;
        }
    
     void Stack::push( )
        {
           int item;
    
           cout<<"\n\n\n\n\n\t Enter value to push onto Stack : ";
           cin>>item;
    
           if(top==(max_length-1))
    	  cout<<"\n\n\t ***  Error : Stack is full. \n"<<endl;
    
           else
    	  {
    	     top++;
    	     stack[top]=item;
    
    	     cout<<"\n\n\t *** "<<item<<" is pushed onto the Stack."<<endl;
    	  }
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::pop( )
        {
           if(top==-1)
    	  cout<<"\n\n\n\t ***  Error : Stack is empty. \n"<<endl;
    
           else
    	  {
    	     cout<<"\n\n\n\t *** "<<stack[top]<<" is poped from the Stack."<<endl;
    
    	     stack[top]=0;
    	     top--;
    	  }
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::print_stack( )
        {
           if(top!=-1)
    	  {
    	     cout<<"\n\n\n\n\n\t Values pushed onto Stack are : \n"<<endl;
    
    	     for(int count=0;count<=top;count++)
    		cout<<"\t Stack ["<<count<<"]  =  "<<stack[count]<<endl;
    	  }
    
           else
    	  cout<<"\n\n\n\n\n\t *** Nothing to show. "<<endl;
    
           cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
    
           getch( );
        }
    
     void Stack::show_working( )
        {
           int Key=NULL;
           do
    	  {
    	     clrscr( );
    
    	     gotoxy(5,5);
    	     cout<<"Sequential Stack"<<endl;
    
    	     gotoxy(10,8);
    	     cout<<"Select one:"<<endl;
    
    	     gotoxy(15,10);
    	     cout<<"- Press \P\ to Push a value"<<endl;
    
    	     gotoxy(15,12);
    	     cout<<"- Press \O\ to Pop a value"<<endl;
    
    	     gotoxy(15,14);
    	     cout<<"- Press \S\ to Print the values"<<endl;
    
    	     gotoxy(15,16);
    	     cout<<"- Press \E\ to Exit"<<endl;
    
    	     Input:
    
    	     gotoxy(10,20);
    	     cout<<"                      ";
    
    	     gotoxy(10,20);
    	     cout<<"Enter your Choice : ";
    
    	     Key=getche( );
    
    	     if(int(Key)==27 || Key=='e' || Key=='E')
    		break;
    
    	     else if(Key=='p' || Key=='P')
    		push( );
    
    	     else if(Key=='o' || Key=='O')
    		pop( );
    
    	     else if(Key=='s' || Key=='S')
    		print_stack( );
    
    	     else
    		goto Input;
    	  }
           while(1);
        }
    
     int main( )
        {
           Stack obj;
    
           obj.show_working( );
    
           return 0;
        }

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    void Stack::Stack( )
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    My teacher has informed me that this program is not acceptable becasue it is object oriented and we were not taught that. Now I have to figure out how to do this simpler and I am running out of time and ideas.

  15. #15
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Also, now I have to do both a sequential stack AND a linked queue.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Syntax for adding a program to autoexec.bat...
    By Sebastiani in forum C Programming
    Replies: 5
    Last Post: 06-18-2002, 12:38 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21