Help please! Prime Numbers

Hi this is my program. (Prime Numbers Application) Where I take limits of two numbers an upper and lower and define the primes with that scope of numbers.

for some reason, however, it seems a little off and i'm getting the following errors. can you explain a little of what my problem may be. Any help is greatly appreciated.

Error 1 - error C2601: 'testValue' : local function definitions are illegal


Error 2 - error C2440: 'return' : cannot convert from 'bool (__cdecl *)(int)' to 'double'


This is my code:


#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required to manipulate C++ stream I/O
#include <string> // required to access string functions
#include <cmath> // required to perform math operations.
#include <windows.h> //will be used to perform a series of beeps that creates a sound byte.


using namespace std;

// defines function prtotype testValue


double testValue (int);
void banner (void);
bool is_Prime(int); // is_prime function prototype? // boolean -- determines if true or false.


// end of function


int main(void)
{
int min = 0,
max = 0;



banner(); // Dispaly title Banner

double testValue (int n)
{
return is_Prime;
}

cout <<"\nEnter a lowerbound value: ";
cin >> min;

cout <<"\nEnter an upperbound value: ";
cin >> max;

while (min < 2 || max < 2 && min > max) // Range of numbers used > 2, max is not specified.

{
cout <<"\nPlease enter a number >= 2. Try again."<< endl << endl;
cout <<"Re-enter lowerbound value: ";
cin >> min;
cout <<"Re-enter upperbound value: ";
cin >> max;
}

return 0;
}


//This is the banner function
void banner (void)
{
system ("color 1F");
cout <<"\n**************************************************";
cout <<"\n* Welcome to the Prime Numbers Application *";
cout <<"\n**************************************************"<< endl << endl;
return;
}

// This is the function for is_prime.
double testValue(int n)
{
bool is_Prime = true;
for ( int i = 2; i <= n; i++)
{
for ( int n = 2; n < i; n++)
{
if ( i % n == 0 )
{
is_Prime = false;
break;
}
}
if (is_Prime)
{
cout <<"The Primes numbers are: "<< i << endl;
}
is_Prime = true;
}

Error 1	- error C2601: 'testValue' : local function definitions are illegal
Error 2	- error C2440: 'return' : cannot convert from 'bool (__cdecl *)(int)' to 'double'


Error 1: Move testValue outside of the main() function. You can put it ahead of the main or put the line:
double testValue(int n); ahead of the main, and put the whole thing at the bottom of the file.

Error 2: Change testValue from : double testValue(int n) to bool testValue(int n)


Result:
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
63
64
65
66
67
68
69
70
71
72
73
#include <iostream> // required to perform C++ stream I/O
#include <iomanip>	// required to manipulate C++ stream I/O
#include <string> // required to access string functions
#include <cmath>	// required to perform math operations.
#include <windows.h> //will be used to perform a series of beeps that creates a sound byte.


using namespace std;

// defines function prtotype testValue
bool testValue (int);
void banner (void);
bool is_Prime(int); // is_prime function prototype? // boolean -- determines if true or false.
// end of function

int main(void)
{
	int min = 0, 
	max = 0;

	banner(); // Dispaly title Banner

	cout <<"\nEnter a lowerbound value: ";
	cin >> min;
	cout <<"\nEnter an upperbound value: ";
	cin >> max;

	while (min < 2 || max < 2 && min > max) // Range of numbers used > 2, max is not specified.
	{ 
		cout <<"\nPlease enter a number >= 2. Try again."<< endl << endl;
		cout <<"Re-enter lowerbound value: ";
		cin >> min;
		cout <<"Re-enter upperbound value: ";
		cin >> max;
	}
	
	//Do something with min/max here and then call testValue(int n) to test a number.
	
	return 0;
}

//This is the banner function
void banner (void)
{
	system ("color 1F");
	cout <<"\n**************************************************";
	cout <<"\n* Welcome to the Prime Numbers Application *";
	cout <<"\n**************************************************"<< endl << endl;
	return;
}

// This is the function for is_prime.
bool testValue(int n)
{
	bool is_Prime = true;
	for ( int i = 2; i <= n; i++)
	{
	for ( int n = 2; n < i; n++)
	{
	if ( i % n == 0 )
	{
	is_Prime = false;
	break;
	}
	}
	if (is_Prime)
	{
	cout <<"The Primes numbers are: "<< i << endl;
	}
	is_Prime = true;
	
	return is_Prime;
}
Topic archived. No new replies allowed.