It’s a very simple program. I have a function defined on the top and in the loop I am calling the function print.
But I am getting the following errors:
prog.cpp:5: error: variable or field ‘print’ declared void
prog.cpp:5: error: ‘a’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp:11: error: ‘print’ was not declared in this scope
Here it is:
#include <iostream>
using namespace std;
void print( a ) {
cout << a << endl;
}
int main() {
for ( int i = 1; i <= 50; i++) {
if ( i % 2 == 0 ) print( i );
}
return 0;
}
You forgot to declare the type of
awhen definingprint.