Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Help with functions!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 11:36 AM

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]

Ad:

#2 boogyman19946   Members   -  Reputation: 400

Like
3Likes
Like

Posted 03 August 2012 - 12:16 PM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#3 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 12:43 PM

I'll do a repost, you were correct.

#4 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 12:44 PM

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;
}


#5 Servant of the Lord   Marketplace Seller   -  Reputation: 8923

Like
0Likes
Like

Posted 03 August 2012 - 12:44 PM

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?

Could you also repost your code, as the above poster said, it looks like you copied+pasted it wrong.
[Edit:] Thanks for reposting it.

Edited by Servant of the Lord, 03 August 2012 - 12:45 PM.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#6 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 12:45 PM

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 ==========

#7 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 12:46 PM

I'm still learning I appreciate the patience :)

#8 Servant of the Lord   Marketplace Seller   -  Reputation: 8923

Like
0Likes
Like

Posted 03 August 2012 - 12:51 PM

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.


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

Edited by Servant of the Lord, 03 August 2012 - 12:53 PM.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#9 Servant of the Lord   Marketplace Seller   -  Reputation: 8923

Like
0Likes
Like

Posted 03 August 2012 - 12:56 PM

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, 03 August 2012 - 12:57 PM.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#10 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 12:58 PM

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.

#11 Servant of the Lord   Marketplace Seller   -  Reputation: 8923

Like
0Likes
Like

Posted 03 August 2012 - 01:03 PM

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. Posted Image

Edited by Servant of the Lord, 03 August 2012 - 01:03 PM.

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#12 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 03 August 2012 - 01:45 PM

My problem has been solved, thanks for all the help!

#13 Mussi   Crossbones+   -  Reputation: 959

Like
5Likes
Like

Posted 03 August 2012 - 02:45 PM

It could be helpful to others if you posted the solution Posted Image.

#14 JonBMN   Members   -  Reputation: 596

Like
0Likes
Like

Posted 06 August 2012 - 12:36 PM

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 :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS