Help with functions!

Started by
12 comments, last by JonBMN 11 years, 8 months ago
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]
Advertisement
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.

Yo dawg, don't even trip.

I'll do a repost, you were correct.
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;
}
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.
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 ==========
I'm still learning I appreciate the patience :)
[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. rolleyes.gif
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?

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.

This topic is closed to new replies.

Advertisement