Parse errors

This is a discussion on Parse errors within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I have been working from the book "C++ without fear" for a couple of weeks, and when i ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    3

    Parse errors

    Hi guys,
    I have been working from the book "C++ without fear" for a couple of weeks, and when i wrote this program from the book:

    Code:
    #include <iostream>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    
    using namespace std;
    
    int rand_0toN1(int n);
    
    int main()  {
       int n, i;
       int r;
    
    
       srand(time(NULL));
    
       cout << "Enter number of dice to roll: ";
       cin >> n;
       for (i = 1; i<=n; i++)  {
          r = rand_0toN1(6) + 1;
          cout << r << " ";
         
       }
       return 0;
    }
    
    int rand_0toN1(int n)  {
       return rand() %n;
    }
    I was told by the compiler that there was a

    "Parse error before '<' "

    On the line saying:

    Code:
    cout << "Enter a number of dice to roll: ";
    This seemed to be completely random as whatever I did to the code it still wouldn't work, but when I wrote another code that was EXACTLY the same it worked perfectly.

    Please help, and I'm still a bit of a newbie, so please don't throw too much jargon at me!

    Many thanks in advance
    NWNN

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,401
    I do not see what could be causing the problem, and testing with the MinGW port of GCC does not show any such error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    3
    why would the error happen generally?

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    9
    hmm i cant see anything (works fine with minGW and dev C++ IDE).
    What compiler are you using?
    I am also working with that book btw.

  5. #5
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    The only thing I can think of is if your compiler is compiling an
    out of date version of the file somehow (this nornally only
    happens in a multi file project). The compiler should have some
    form of a Clean or Rebuild All command - try using it and it
    may fix the issue. parse errors generally refer to syntax errors
    such as a missing semicolon
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    3
    I'm using Dev C++, but i just switched to visual basic so i'm gonna use that now. Thanks very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. C Parse errors
    By aimalk in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 04:23 PM

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