Thread: Parse errors

  1. #1
    Registered User
    Join Date
    May 2006

    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:

    #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;
       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:

    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    I do not see what could be causing the problem, and testing with the MinGW port of GCC does not show any such error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

  4. #4
    Registered User
    Join Date
    Apr 2006
    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
    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 ();

    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
    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, 05:23 PM