473,669 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cant understand this one

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\Ex 3_18\Makefile.w in"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in" 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
Jul 19 '05 #1
4 2398

"Rich" <RE************ **@yahoo.co.uk> wrote in message
news:bf******** **@pheidippides .axion.bt.co.uk ...
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 ;

You can define a function within a function or indeed main(), so remove from
here
int integerPower ( int base, int component )
{
int ans = base ;
for ( i = component; i >=1; --i )
{
ans *= base ;
}

return ans;
}
to here, and then place it at the end of the file
Allan

system("PAUSE") ;
return 0;
}

and here is the compile log

Compiler: Default compiler
Building Makefile: "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in" all
g++.exe -c ex3_18.cpp -o
3_18.o -I"K:/Eric/Dev-Cpp/include/c++" -I"K:/Eric/Dev-Cpp/include/c++/ming 32" -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

Jul 19 '05 #2
Allan Bruce wrote:
"Rich" <RE************ **@yahoo.co.uk> wrote in message
news:bf******** **@pheidippides .axion.bt.co.uk ...
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 ; cin >> x >> y;

cout << integerPower ( x, y ) << endl ;

You can define a function within a function or indeed main(), so remove from

^^^^^
can't
here

int integerPower ( int base, int component )
{
int ans = base ;
for ( i = component; i >=1; --i )
{
ans *= base ;
}

return ans;
}

to here, and then place it at the end of the file
Allan
system("PAUSE") ;
return 0;
}

and here is the compile log

Compiler: Default compiler
Building Makefile: "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in" all
g++.exe -c ex3_18.cpp -o


3_18.o -I"K:/Eric/Dev-Cpp/include/c++" -I"K:/Eric/Dev-Cpp/include/c++/ming

32" -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(cons t
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

See above.
HTH,
--ag
--
Artie Gold -- Austin, Texas

Jul 19 '05 #3
cin >> x >> y;

Thanks :)
You can define a function within a function or indeed main(), so remove
from ^^^^^
can't

Ahhh I did wonder if Allan might have meant can't, as it was already
defined in main

I forgot that it is not allowed to define a function within a function, and
that main is itself a function

cheers guys

Rich See above.
HTH,
--ag
--
Artie Gold -- Austin, Texas

Jul 19 '05 #4

"Artie Gold" <ar*******@aust in.rr.com> wrote in message
news:3F******** ******@austin.r r.com...
Allan Bruce wrote:
"Rich" <RE************ **@yahoo.co.uk> wrote in message
news:bf******** **@pheidippides .axion.bt.co.uk ...
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 ; cin >> x >> y;

cout << integerPower ( x, y ) << endl ;

You can define a function within a function or indeed main(), so remove from ^^^^^
can't
here

int integerPower ( int base, int component )
{
int ans = base ;
for ( i = component; i >=1; --i )
{
ans *= base ;
}

return ans;
}

to here, and then place it at the end of the file
Allan
system("PAUSE") ;
return 0;
}

and here is the compile log

Compiler: Default compiler
Building Makefile: "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in"
Executing make...
make.exe -f "M:\C++\How To Program\CH03\Ex 3_18\Makefile.w in" all
g++.exe -c ex3_18.cpp -o


_18.o -I"K:/Eric/Dev-Cpp/include/c++" -I"K:/Eric/Dev-Cpp/include/c++/ming
2" -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(cons t
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

See above.
HTH,
--ag
--
Artie Gold -- Austin, Texas


Er, yup thats what I meant ;-)
Allan
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1106
by: CMEDIA_SOUND | last post by:
I have a peculiar problem, I have a tabpage with a label control on it. When i set a background image to the tabpage and drag the label around it has paint issues in that it is slow, granted the image i am using is 5mb!!! HOWEVER... I have inherited the tabpage created an Image reference in it, and overrriden the onPaint method to draw the image now if i press a button that sets the background image of the control
7
1768
by: William.Zhang | last post by:
the following code: template <class T> class test{ typedef T::XXX x; }; int main(){ return 0; }
6
1260
by: Klaas | last post by:
I want the backgrond of my whole page in gradient. In the source tab I have: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head>
6
3132
by: ancelotp | last post by:
hi, i'm new to sql i'd appretiate if someone would helpme out with this doudt i have CODE: CREATE TABLE entry ( uno int(6) NOT NULL auto_increment, fname varchar(30) NOT NULL, sname varchar(30) NOT NULL, email varchar(30) NOT NULL ,
1
2137
by: erotikaboi | last post by:
Guys, Firstly let me say I am a photographer so if you can offer me a solution I will really appreciate it in simple english not techiespeak as I wont understand it. Thanks. Ok, I am using Access from the Office XP suite on a pentium 4 running WinXP Home. We have a database which has been running successfully for approx 12 months now. Suddenly when I tried to generate a report or query using a wizard I get the mssg "Active X cant create...
3
1927
H0kage
by: H0kage | last post by:
Hello everyone got an assignment for college where i cant find the way to make JDeveloper to understand where the words are separated.This What The Assignment Asks.Any Tip or example to help me finish it would be greatly apreaciated.Thank you in advance. Following is an example of screen results that might appear, depending on the data the user inputs. This program asks the user for three words.
8
4550
by: Jim Florence | last post by:
Hi, I've just add a couple of dropdowns to my ASP form, set up a sqldatasource and bound to the dropdown and it all works great. I want the first item of the dropdown to be blank soa fter reading a few articles the DropDownList1.SelectedIndex = -1 seems the way to go. I've tried setting this oin the asp page and on a page load event in the vb behind but I still cant get a blank dropdown
12
2082
by: lalou89 | last post by:
Develop a simple text editor program. The program will show the user a menu of choices and will act according to his choice. Use functional decomposition to break the system into small functions that are accessed by the main program to provide the system functionality. Using the text editor, the user can: • Input the name of a file • The program will check if a file with this name exists or not. If yes, it will tell the user “This File...
0
1148
Sakalicek
by: Sakalicek | last post by:
Hello all, I have serious problem and have no idea how to solve it, of course :) I have Web Service which has master page. This side is the client side. On master page there are some submit buttons, comboBoxes to choose language e.t.c. and also link to another page. If I click at link to some page, but just on my computer, it all goes well. But if I try it on PC which is connected to my customer´s network, Web Service should send request...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.