error: a function-definition is not allowed here before ‘{’ token

Im getting this error and im not sure how to fix it

In function ‘int main()’:
25:2: error: a function-definition is not allowed here before ‘{’ token
{
^
69:1: error: expected ‘}’ at end of input
}
^

Also, im adapting my code from an old assignment into my new assignment. My assignment is to "Write a program that prints all the prime numbers in the range of two user defined numbers: low and
high. Create a function that checks for a number to be prime or not."

so any tips on how to make my code do that would be greatly appreciated



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #include <iostream>
#include <cstdlib>  
#include <ctime>  

using namespace std;

void printRandomNumber(int low, int high);

int main (){
	int low,high;
	
	cout<<"Enter the lower number? ";
	cin >> low;
	cout<<"Enter the higher number? ";
	cin >> high;
	
	bool isPrime(int n)
	{
		int i,count=0;
		if(n==1)
			return false;
		if(n==2)
			return true;
		if(n%2==0)
			return false;
		for(i=2;i<=n;i++)
		{
			if(n%i==0)
				count++;
		}
		if(count==2)
			return true;
		else
			return false;
	}
	
	if(high > low)
	{
		if(isPrime(randNum))
			printRandomNumber(low, high);
	} 
	else //in case the lower is greater than the upper
	{
		while(lower > upper);
		{
			cout<<"Invalid input. Second value should be greater than first value."<<endl;
			cout<<"Enter the lower number? ";
			cin >> lower;
			cout<<"Enter the higher number? ";
			cin >> upper;
		}
	}
	
	return 0;
}

void printRandomNumber(int lower, int upper)
{
srand (time(NULL));
int randNum = rand() % (upper-lower) + lower;
cout<<"Your random number is "<<randNum<<endl;
}
Line 17: You can't define functions inside other functions. Move this definition out of main().
Topic archived. No new replies allowed.