# Help with functions!

This topic is 2021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a program I'm trying to create. here is the main program..

[source lang="cpp"] learn.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

#include "stdafx.h"

void BigDog(int KibblesCount);

//
int _tmain(int argc, _TCHAR* argv[])
{
BigDog(3);
return 0;
}[/source]

here is the funtion..

[source lang="cpp"]// BigDog.cpp

#include <stdafx.h>
#include <iostream>

using namespace std;

void BigDog(int KibblesCount)
{
cout << "I'm a lucky dog" <<endl;
cout << "I have " << KibblesCount << "pieces of food" << endl;
}[/source]

##### Share on other sites
It seems to me like something went wrong when you copied the code. You have two _tmain functions, include stdafx twice and BigDog.cpp is missing files to be included and overall just looks like only half of it made it to the forum.

##### Share on other sites
I'll do a repost, you were correct.

##### Share on other sites
program

 // learn.cpp : Defines the entry point for the console application. // #include "stdafx.h" void BigDog(int KibblesCount); int _tmain(int argc, _TCHAR* argv[]) { BigDog(3); return 0; } 

function

 // BigDog.cpp #include <stdafx.h> #include <iostream> using namespace std; void BigDog(int KibblesCount) { cout << "I'm a lucky dog" <<endl; cout << "I have " << KibblesCount << "pieces of food" << endl; } 

##### Share on other sites
You never mentioned what problem you are having.

Are you getting an error message (and if so, could you post it?), or is it compiling but not working how you expect it to?
What is the result you are expecting it to do, and what is the result that it is actually giving?

[s]Could you also repost your code, as the above poster said, it looks like you copied+pasted it wrong.[/s]
[Edit:] Thanks for reposting it. Edited by Servant of the Lord

##### Share on other sites
error code I'm getting.. even though I've added the BigDog.cpp to the project multiple times..

1>------ Build started: Project: learn, Configuration: Debug Win32 ------
1> BigDog.cpp
1>c1xx : fatal error C1083: Cannot open source file: '..\..\BigDog.cpp': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

##### Share on other sites
I'm still learning I appreciate the patience

##### Share on other sites
[s]Your code looks correct. What are you expecting it to do, and what result are you actually getting?

If your window opens and closes too fast for you to see anything, try running it from the command line or adding system("pause"); at the end of _tmain() before you return.
system("pause"); should not actually be used in any real code you release to people (and so many programmers are against it), but when learning C++ I found it very useful.
One of the reasons it shouldn't be used when releasing code to people, is because it actually launches a another program (called 'pause') which could do many things you aren't expecting if 'pause' is missing or replaced maliciously with something else. But for your own practice, it works fine until you learn proper control loops.[/s]

[Edit:] Dang, keep on posting late and the forum software apparently no longer warns me of new posts, and has no 'delete post' button. Edited by Servant of the Lord

##### Share on other sites
Your error has to do with the compiler properly locating your second file 'BigDog.cpp'.
This doesn't have to do with your C++ code itself, but rather how your IDE is telling the compiler where to find the source files.

Are both main.cpp and BigDog.cpp located in the same folder, and are both of them added to your Visual Studio project?
Is 'BigDog.cpp' actually named 'BigDog.cpp' or is it mistakenly named something else?

What version of Visual Studio are you using? Edited by Servant of the Lord

##### Share on other sites

Your error has to do with the compiler properly locating your second file 'BigDog.cpp'.
This doesn't have to do with your C++ code itself, but rather how your IDE is telling the compiler where to find the source files.

Are both main.cpp and BigDog.cpp located in the same folder, and are both of them added to your Visual Studio project?
Is 'BigDog.cpp' actually named 'BigDog.cpp' or is it mistakenly named something else?

Thank you for the clarification. Yes, they are both in the same folder and added to the project using the project drop down menu - add existing. I've checked it multiple times to see if they are the correct file names and they are.

##### Share on other sites
It looks like your IDE is trying to look for BigDog.cpp in the wrong directory, '..\..\BigDog.cpp', but I don't use Visual Studio and this is a Visual Studio-specific problem.
Perhaps someone with more experience with that IDE can offer assistance. Sorry I can't be of more help. Edited by Servant of the Lord

##### Share on other sites
My problem has been solved, thanks for all the help!

##### Share on other sites
Using MVS C++ ide I had to take off the function program, then put it back on multiple times till the ide found the program in the right place. That was my solution