Sign in to follow this  
JonBMN

Help with functions!

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 this post


Link to post
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 this post


Link to post
Share on other sites
program

[CODE]
// 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;
}
[/CODE]

function

[CODE]
// 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;
}
[/CODE]

Share this post


Link to post
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]
[b][Edit:][/b] Thanks for reposting it. Edited by Servant of the Lord

Share this post


Link to post
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 this post


Link to post
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 [b]system("pause");[/b] 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]

[b][Edit:][/b] Dang, keep on posting late and the forum software apparently no longer warns me of new posts, and has no 'delete post' button. [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] Edited by Servant of the Lord

Share this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1344020193' post='4965919']
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?
[/quote]

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 this post


Link to post
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. [img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img] Edited by Servant of the Lord

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this