-
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
-
I do not see what could be causing the problem, and testing with the MinGW port of GCC does not show any such error.
-
why would the error happen generally?
-
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.
-
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
-
I'm using Dev C++, but i just switched to visual basic so i'm gonna use that now. Thanks very much!