# Thread: Noob problem - function call

1. ## Noob problem - function call

Hi,

I am trying out a recommended book, "C++ Without Fear," and am having a problem with one of the exercises in the book and on the cd.

The exercise states "Write a function named print_out that prints all the whole numbers from 1 to N. Test the function by placing it in a program that passes a number n to it, where this number is entered from the keyboard. The print_out function should have type void; it does not reutrn a vlaue. The function can be called a simple statement: print_out(n);"

Having a bit of difficult doing this on my own, I copied and pasted the exercise from the cd that came with the book.

Code:
```// Exercise 04.01.02
// This program prints out numbers from 1 to n,
//  by calling a function.

#include <iostream>
using namespace std;

// Function must be declared before being used.

void print_out(int n);

int main() {
int n;

cout << "Enter a number and press ENTER: ";
cin >> n;

print_out(n);

return 0;
}

// Print-out function.
// Prints numbers from 1 to n.

int print_out(n) {
int i;

for (i = 1; i <= n; i++)     // For i = 1 to n,
cout << i << " ";        //   print i
return sum;
}```
When I try to compile it, it highlights "int print_out(n)" and says, "int print_out redeclared as different kind of symbol."

I don't really know what that means, and am confused as well since I am using the sample provided on the cd, so wonder why it isn't compiling. I am using Dev C++ 4.9.9.2.

2. Code:
```void print_out(int n) {
int i;

for (i = 1; i <= n; i++)     // For i = 1 to n,
cout << i << " \n";        //   print i

}```

3. Take a close look:
Code:
`int print_out(n) {`
This should be like the function prototype instead, i.e.
Code:
`void print_out(int n) {`
But if print_out's return type is void, then:
Code:
`return sum;`
Must be wrong. In fact, methinks you can safely remove it.

4. > void print_out(int n);
Here you say it returns void

> int print_out(n)
Here you say it returns int

Pick one as being right, and change the other to match it.

5. Thanks to all of you. Now it works as it should (and better than that, I now get it).

And yeah, that 'return sum' was left over from an earlier exercise. Quite out of place, eh? Whoever edited the stuff that went on the cd did a bit of a sloppy job, methinks, as I've found that a couple exercises are even missing completely.