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.