A simple compiler error : ISO c++ forbids declaration


Hi, I just started learning C++ so this question might be too simple for you.
I wrote a simple program to practice function and value passing but got strange errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# include <iostream>
using namespace std;

dogage (int i)  // prototype;

int main ()

{
  int i;
  cout<< "Please input the age: "<<endl;
  cin>>i;

  dogage (i);

  return 0; 

}
 

dogage (int m)
  {int dog_age;
   dog_age=m*7;
   cout<< "The age for the dog is: "<< dog_age<<". " <<endl;
   return 0;
  }



Errors are:

ch17_ex1.cpp:6:1: error: expected constructor, destructor, or type conversion before 'int'.
ch17_ex1.cpp:20:14: error: ISO C++ forbids declaration of 'dogage' with no type [-fpermissive].

I tried so many things including adding/cutting headers or deleting "using namespace std;" line. But it still doesn't work.

Anyone can tell me what causes the errors?

Many thanks!
a function needs a return type:

void dogage (int i);

and the prototype a semicolon
It's so interesting that I have to declare return type in both the prototype and
function definition lines.
But it finally works. Thank you so very much!
Topic archived. No new replies allowed.