R
Rich
Hi all
I am using DEVCPP 4.9.8.1 which uses MingW32 GCC 3.2 compiler
I am trying to compile this program, but without success, I am sure the
compiler is set up ok, as I can compile and run hello.cpp fine
here is the listing please can someone tell what I am doing wrong please
#include <iostream>
#include <cstdlib>
using namespace std;
int integerPower ( int, int ) ;
int main( void )
{
int x, y ;
cout << "First enter the base number, folowed by the component: " << endl
;
cin >> x, y ;
cout << integerPower ( x, y ) << endl ;
int integerPower ( int base, int component )
{
int ans = base ;
for ( i = component; i >=1; --i )
{
ans *= base ;
}
return ans;
}
system("PAUSE");
return 0;
}
and here is the compile log
Compiler: Default compiler
Building Makefile: "M:\C++\How To Program\CH03\Ex3_18\Makefile.win"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex3_18\Makefile.win" all
g++.exe -c ex3_18.cpp -o
x3_18.o -I"K:/Eric/Dev-Cpp/include/c++" -I"K:/Eric/Dev-Cpp/include/c++/ming
w32" -I"K:/Eric/Dev-Cpp/include/c++/backward" -I"K:/Eric/Dev-Cpp/include"
ex3_18.cpp: In function `int main()':
ex3_18.cpp:18: parse error before `{' token
ex3_18.cpp:20: `component' undeclared (first use this function)
ex3_18.cpp:20: (Each undeclared identifier is reported only once for each
function it appears in.)
ex3_18.cpp:22: `ans' undeclared (first use this function)
ex3_18.cpp:22: `base' undeclared (first use this function)
ex3_18.cpp: At global scope:
ex3_18.cpp:27: ISO C++ forbids declaration of `system' with no type
ex3_18.cpp:27: `int system' redeclared as different kind of symbol
K:/Eric/Dev-Cpp/include/stdlib.h:373: previous declaration of `int
system(const
char*)'
ex3_18.cpp:27: invalid conversion from `const char*' to `int'
ex3_18.cpp:28: parse error before `return'
make.exe: *** [ex3_18.o] Error 1
Execution terminated
I notice that it is moaning about component, which is being passed in to the
function as an argument, I didnt think I needed to declare component first,
as I have already done so in the function prototype, like I say this one has
confused me
TIA
I am using DEVCPP 4.9.8.1 which uses MingW32 GCC 3.2 compiler
I am trying to compile this program, but without success, I am sure the
compiler is set up ok, as I can compile and run hello.cpp fine
here is the listing please can someone tell what I am doing wrong please
#include <iostream>
#include <cstdlib>
using namespace std;
int integerPower ( int, int ) ;
int main( void )
{
int x, y ;
cout << "First enter the base number, folowed by the component: " << endl
;
cin >> x, y ;
cout << integerPower ( x, y ) << endl ;
int integerPower ( int base, int component )
{
int ans = base ;
for ( i = component; i >=1; --i )
{
ans *= base ;
}
return ans;
}
system("PAUSE");
return 0;
}
and here is the compile log
Compiler: Default compiler
Building Makefile: "M:\C++\How To Program\CH03\Ex3_18\Makefile.win"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex3_18\Makefile.win" all
g++.exe -c ex3_18.cpp -o
x3_18.o -I"K:/Eric/Dev-Cpp/include/c++" -I"K:/Eric/Dev-Cpp/include/c++/ming
w32" -I"K:/Eric/Dev-Cpp/include/c++/backward" -I"K:/Eric/Dev-Cpp/include"
ex3_18.cpp: In function `int main()':
ex3_18.cpp:18: parse error before `{' token
ex3_18.cpp:20: `component' undeclared (first use this function)
ex3_18.cpp:20: (Each undeclared identifier is reported only once for each
function it appears in.)
ex3_18.cpp:22: `ans' undeclared (first use this function)
ex3_18.cpp:22: `base' undeclared (first use this function)
ex3_18.cpp: At global scope:
ex3_18.cpp:27: ISO C++ forbids declaration of `system' with no type
ex3_18.cpp:27: `int system' redeclared as different kind of symbol
K:/Eric/Dev-Cpp/include/stdlib.h:373: previous declaration of `int
system(const
char*)'
ex3_18.cpp:27: invalid conversion from `const char*' to `int'
ex3_18.cpp:28: parse error before `return'
make.exe: *** [ex3_18.o] Error 1
Execution terminated
I notice that it is moaning about component, which is being passed in to the
function as an argument, I didnt think I needed to declare component first,
as I have already done so in the function prototype, like I say this one has
confused me
TIA