C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 11th, 2007, 08:54 AM
*shon* *shon* is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 2 *shon* User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 3 sec
Reputation Power: 0
General - Insert Include-File

I was trying to insert a file into another one with the 'include-function, but DEV is sending out error messages one by one..
. I'm writing down the codes..hope someone can help me.

This is the file called 'includedatei.cpp', which is to be included:

Quote:
// Includefile - The file, which is to be included.

int addition()
{
return (zahl + zahl);
}

int square()
{
return (zahl * zahl);
}


This is the file called 'includetest.cpp', where the latter has to be inserted:

Quote:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "includedatei"

using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
int zahl;

cout << "The File 'Include-Datei' is included. \n\n";
cout << "Zahl: ";
cin >> zahl;

cout << "\nZahl + Zahl: " << addition();
cout << "\nZahl * Zahl: " << square();
cout << "\nByebye!!!\n\n";
system("PAUSE");
return 0;

}


I just can't figure out what's wrong...I'm new to C++ programming btw, so try to forgive me for posting such a silly thread
Would appreciate every bit of help..thankyou : )

Reply With Quote
  #2  
Old September 12th, 2007, 12:54 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
Hi, welcome to the forums. First of all it would be better if you would also post the error messages you are getting
Second, I am guessing that the problem is in the two functions in the include file. They refer to a variable called zahl, but that variable is only declared in main. There are a couple of ways to deal with this, but I would make zahl a parameter to those functions. Btw, it is customary to call the include file includedatei.h or includedatei.hpp.

Example:
Code:
int addition(int paramZahl)
{
    return (paramZahl + paramZahl);
}

and you call this function from main like:
Code:
int main(int nNumberofArgs, char* pszArgs[])
{
    int zahl;
    .
    .
    cout << "\nZahl + Zahl: " << addition(zahl);


I named the parameter 'paramZahl' to make things more clear. You could also call it just zahl of course.

Good luck
__________________
There is no such thing as C/C++, you either program C or C++

Reply With Quote
  #3  
Old September 12th, 2007, 02:13 PM
*shon* *shon* is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 2 *shon* User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 3 sec
Reputation Power: 0
First of all, thanks for replying
I'll post error codes from now on..oh and as for the ".h", I did know 'bout it, but considered to keep things easy, as I've just started learning C++

Alrite, so you renamed the 'zahl' variable to 'paramzahl', but thats just a formal thing, isn't it?
Then, I tried out your version, but it's still giving an error message:

Quote:
'addition' undeclared (first use this function)
(Each undeclared identifier is reported only once for each funtion it appears in.)
'square' undeclared (first use this function)


The problem to me seems to be the fact, that the main file isn't able to track the include file. I did enter the include-command properly, didn't I?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - Insert Include-File


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap