Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Compile Error: Local Function definition problems? :|||COL|||2

[b][red]This message was edited by BigVent at 2003-1-25 19:16:46[/red][/b][hr]

Can anyone please tell me what I am doing wrong? (I'm sure it's multiple things but I'm getting compile errors regarding functions "printout" & "main".) Any help is appreciated & Thanks in advance!
[code]
//Function program that requires an input from keyboard
//and prints all the Prime Numbers up to the inputted value.
//Project #1

#include
#include
using namespace std;

//get_value function, get's the inputted value from the keyboard
//for this exercise the value of size should not exceed 500.
void get_value(int size)
{
cout << "Please input a value: ";
cin >> size;
if (size > 500 || size < 1)
cout << "You Entered an Incorrect Value!";
return;
}

//fill_array function, fills the array
//with the "size" inputted from keyboard setting
//each subscript value equal to one.
void fill_array(int arr[], int size)
{
int i;
for (i = 2; i < size; i++)
arr[i] = 1;
}

//prime function, starts with subscript #2 through the "size"
//inputted from keyboard & "if" the subscript's value is
//divisible by either a (2 - or - 3) the value of subscript
//will be set to zero... else set value is equal to one
int prime (int p_factor)
{
int i,p;
for (i = 2; i < p_factor; i++)

if (p % i == 0)
return 0;
return 1;
}

//Sieve of Eratosthenes function, takes array & size as input.
//this function starts with subscript #2 & loops through
//the array & sets to zero every element whose value
//subscript is a multiple of that subscript for the element value 1.
//array continues until it has reached the input value.
void sieve(int arr[], int size)
{
int i, j;
for (i = 2; i < size; i++)
{
if (arr[i] == 1 && prime(i))

for (j = i + 1; j < size - 1; j++)
j++;
if ( j % i == 0 && arr[i] == 1)
arr[j] = 0;
else
{
arr[i] = 0;
}
}

//printout function, prints out the index of the array
//only if the value of the subscript is equal to one.
//also only prints ten "Prime" numbers per line.
void printout(int arr[], int size)

//Project1.cpp(76) : error C2601: 'printout' : local
//function definitions are illegal
//when you click on this statement it points to here ---->
{
int count = 0;
for (int i = 2; i < size; i++)
{
if (arr[i] == 1)
{
cout << setw(4) << i;
}
count++; //bumps counter for times outputted

//purely for neatness & it was required
//to only have ten prime values printed
//per line so the above counter "j" was used.
if (count > 10)
{ cout << endl;
} }

//main function, calls on functions to complete tasks
void main ()
{
int size;
int arr[size + 1] = {0};

get_value(size);
fill_array(array, size);
sieve(array, size);
printout(array, size);
}
}

//Project1.cpp(119) : fatal error C1004: unexpected end of file found
[/code]





Comments

  • [b][red]This message was edited by pseudocoder at 2003-1-26 15:0:21[/red][/b][hr]
    : [b][red]This message was edited by BigVent at 2003-1-25 19:16:46[/red][/b][hr]

    Your first function void getvalue(int size) is doing two things

    void functions don't return a value, so you don't need to use return.

    while the second part isn't really an error

    void getvalue(int size)

    cout << "enter a value: ";
    cin >> size;

    this function is passing a value into size, but you're asking for a new value. Did you mean to do that?

    [code]int getValue(void)
    {
    int size;
    cout << "enter a value: ";
    cin >> size;

    if(size < 1 || size > 500)
    // correcterror
    return size;
    }[/code] I'll have to read some more code with a magnifying class. This code block stuff is small :)




  • : Your first function void getvalue(int size) is doing two things
    :
    : void functions don't return a value, so you don't need to use return.
    :
    : while the second part isn't really an error
    :
    : void getvalue(int size)
    :
    : cout << "enter a value: ";
    : cin >> size;
    :
    : this function is passing a value into size, but you're asking for a new value. Did you mean to do that?
    :
    : [code]int getValue(void)
    : {
    : int size;
    : cout << "enter a value: ";
    : cin >> size;
    :
    : if(size < 1 || size > 500)
    : // correcterror
    : return size;
    : }[/code] I'll have to read some more code with a magnifying class. This code block stuff is small :)
    :
    :
    :
    :
    yeah, I meant to do it... but I am a newb. If you see me do something wrong please correct me! Thanks!
This discussion has been closed.