Thread: Noob problem - function call

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    7

    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.
    Last edited by Ultraman; 05-20-2006 at 02:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. call to realloc() inside a function: memory problem
    By simone.marras in forum C Programming
    Replies: 15
    Last Post: 11-30-2008, 10:01 AM
  2. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM