Thread: 1 Error : Declaration Terminated Incorrectly

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    9

    1 Error : Declaration Terminated Incorrectly

    Hi,
    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    class password
    {
    int main(void)
    {
    beginning:
    system("CLS");
    system("TITLE Enter Password");
    string password;
    string playgames;
    cout<< "LOGON: ";
    cin>> password;
    if (password == "passwordhere")
    {
    system("TITLE Welcome");
    system("CLS");
    cout << "Welcome, master HAXIFIX" << endl;
    system("PAUSE");
    goto playgames;
    }
    else
    {
    cout << "Incorrect Username" << endl;
    cout << "-- CONNECTION TERMINATED --" << endl;
    system("PAUSE");
    goto exit;
    }
    exit:
    return 0;
    goto playgames:
    system("CLS");
    system("TITLE Hello, Mr. HAXIFIX");
    cout << "Would you like to play a game?" << endl;
    cout << "Answer: ";
    cin >> playgames;
    if (playgames == "Yes" || playgames == "yes"){
    whatgame;
    }
    else
    {
    cout << "Ok, I will ask later." << endl;
    system("PAUSE");
    playgames;
    }
    whatgame:
    system("PAUSE");
    return 0;
    
    };

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It looks like this scoop and poop code, except for the fact that you just put "class password" in at the start without thinking about what that would mean (like why is main INSIDE a class).

    I suppose you're also a TurboC user as well.
    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.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The main recommendation for this code would be to set it on fire. You've got
    • iostream.h (which you shouldn't)
    • conio.h (which you shouldn't)
    • string.h (which you shouldn't)
    • A lack of <iostream>
    • A lack of <string>
    • A lack of indentation
    • labels, which lead to
    • goto commands, instead of loops
    • do nothing commands, like "whatgame;"
    • system commands (for things that you don't actually appear to need system commands for EDIT: or maybe so)
    • missing semicolons at the end of some commands
    • your main function inside of a class
    • reusing names for both classes and variables
    • code after a return statement (which will therefore never be executed)

    I may have missed a couple.
    Last edited by tabstop; 06-30-2011 at 08:55 AM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    You can not define your main() function inside your class and I would recommend that you investigate loops to rid yourself of your goto statements. Also to use the string class in this old compiler you will need to include the proper header file. I would recommend that you replace your compiler at the earliest possible time, now would be a great time. There are several free current standard compliant compilers available that you can choose.


    Jim

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    9
    Just make that code run, I use 'turbo C'. remove the errors, so that I can run it.
    ty

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Sorry, this isn't a board where you can just show up with some code you found on the net and demand people fix it for you.
    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.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    9
    So what is use of the board. I can better find a place where there are people for helping. It do not help me much.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You learn by reading the books and tutorials, and trying the exercises.
    When you get stuck, you post YOUR OWN code on sites like this, and you ask some questions relating to your code.

    You do NOT learn a damn thing by simply copy/pasting code from one site to another site and then DEMANDING people fix it for you.

    If you find a board that panders to your "me me me" approach, good luck, but it won't make you a programmer.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me ! some declaration error
    By noobnewrecruit in forum C++ Programming
    Replies: 4
    Last Post: 11-14-2010, 05:19 AM
  2. bcc 5.5 Declaration terminated incorrectly
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-28-2008, 04:45 PM
  3. error declaration terminated incorrectly help
    By belfour in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2002, 09:07 PM
  4. Declaration terminated incorrectly
    By Griffin2020 in forum C Programming
    Replies: 8
    Last Post: 04-26-2002, 11:53 PM
  5. declaration terminated incorrectly
    By Clane in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2002, 12:09 AM