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:
# include <iostream>
usingnamespace 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;
}
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.
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!