|
-
December 7th, 2008, 01:57 PM
#1
[RESOLVED] Boolean functions aren't found by main()
I am writing a program that is supposed to find the prime numbers between 1 and 100 using a boolean function. However, when I call the boolean function through int main(), I get the following errors:
error C3861: 'check_prime': identifier not found
error C2365: 'check_prime' : redefinition; previous definition was 'formerly unknown identifier'
The first error points to the function call in main, and the second error points to the curly brace's line after the declaration of the bool function.
Code:
/* File: primes.cpp
* ______________________
* This programs finds the
* prime numbers between 1-100
* using a function.
*/
#include <stdio.h>
#include <math.h>
#include "simpio.h"
#include "genlib.h"
int main()
{
int counter = 0;
bool prime = false;
int divisibleBy;
printf("The prime numbers in the range of 1-100 are:\n");
for (counter = 0; counter <= 100; counter++)
{
prime = check_prime(counter); //error C3861, call to function (check_prime)
if (prime == true)
{
printf("%d\n", counter);
}
else { }
}
}
bool check_prime (int counter)
{ //error C2365 points to this line
int divisibleBy = 0;
int div;
for (div = 1; div <= counter; div++)
{
if (counter % div == 0) divisibleBy++;
}
if (divisibleBy == 2) {
return (true);
}
else {
return (false);
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|