help: parse error at end of input

This is a discussion on help: parse error at end of input within the C++ Programming forums, part of the General Programming Boards category; I got the error at the end of the lines, what's wrong? Code: #include <stdio.h> #include <iostream> #include <math.h> #include ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    25

    help: parse error at end of input

    I got the error at the end of the lines, what's wrong?

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <math.h>
    #include <time.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <iomanip>
    #include <string>
    
    class deck
    {
        public:
    
           enum Card_Type {hearts, diamonds, spades, clubs};
    
           Card_Type theType[4];
           int theRank[13];
    
           deck()
           {
             initialize();
           }
    
        private:
           void initialize (){
             for (int i = 0; i < 3; i++)
             {
               switch (i){
                 case 0:  theType[i] = hearts;
                          break;
                 case 1:  theType[i] = diamonds;
                          break;
                 case 2:  theType[i] = spades;
                          break;
                 case 3:  theType[i] = clubs;
                          break;
             }
    
             for (int i = 0; i < 12; i++)
             {
               theRank[i] = i;
             }
           }
    };
    
    void retriev (deck& in)
    {
    
      srand(time(NULL));
      cout<<"Random selection from a deck!\n";
      cout<<"You got "<<in.theRank[rand()%12]<<" of "<<in.theType(rand()%3);
    }
    
    int main()
    {
      deck one;
      retriev (one);
      system("pause");
      return 0;
    }
    Last edited by f6ff; 06-03-2006 at 07:36 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > void main()
    main returns int

    > case: 0
    Try
    case 0:

    Also, your loop/case is a complete waste of time, it reduces to
    theType[0] = hearts;
    theType[1] = diamonds;
    theType[2] = spades;
    theType[3] = clubs;
    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.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Quote Originally Posted by Salem
    > void main()
    main returns int

    > case: 0
    Try
    case 0:

    Also, your loop/case is a complete waste of time, it reduces to
    theType[0] = hearts;
    theType[1] = diamonds;
    theType[2] = spades;
    theType[3] = clubs;
    error fixed,but the same error is still there

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    I believe you are missing a closing brace in your initialize() function. Following Salems advice would reduce the number of code blocks there are, so you should probably listen to him. Making things easier to read automatically leads to better syntax.
    Last edited by whiteflags; 06-03-2006 at 07:54 AM. Reason: my terrible spelling

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Count the braces in void initialize

    Code:
    // 1
    void initialize () {
    }
    
    // 2
    void initialize () {
      for (int i = 0; i < 3; i++) {
      }
    }
    
    // 3
    void initialize () {
      for (int i = 0; i < 3; i++) {
        switch (i){
        }
      }
    }
    
    // Not like this
    void initialize () {
      for (int i = 0; i < 3; i++) {
        switch (i){
    If you type your closing brace whenever you type the opening brace, you'll never get into this state of having mis-matches or the problems of figuring out exactly where the missing one would go.
    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.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    problem solved, thx.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    BTW you should only call srand() once during the execution of a program, so if you intend to call retriev() multiple times you should put the srand() call in main().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  4. syntax error at end of input
    By cerin in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2005, 12:06 AM
  5. Reading integers until end of input
    By nivo in forum C Programming
    Replies: 7
    Last Post: 10-20-2001, 04:18 PM

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