Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,431 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,918 people online right now. Registration is fast and FREE... Join Now!




Too few arguments?

 
Reply to this topicStart new topic

Too few arguments?, function practice

Delta_Echo
13 Jan, 2008 - 12:14 AM
Post #1

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 439


My Contributions
I have been practicing with c++ function design.
Run into a it of a problem....the programming gods hate me! lol


CODE

main.cpp :

#include <iostream>
#include <stdlib.h>
#include "func1.h"
#include "func2.h"

using namespace std;

int main()
{
  int value1;
  bool value2;
  float value3;
  char body[5];
  tst1();
  cout << value1 << endl;
  cout << value2 << endl;
  cout << value3 << endl;
  tst2();
  cout << body << endl;
  cin.getline ( body, 5, '\n' );
  cin.get();
}

func1.h :

char tst2( char body[5] )
{
   body = "HELP!";
}

func2.h :

int tst1( int value1, bool value2, float value3 )
{
    value1 = 21;
    value2 = true;
    value3 = 21.111;
}        


Thanks for reading, please help!

Now to start the sacred ritual of compiling the holy source code of the linux kernel to try and make the programming gods happy.....

lol smile.gif
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Too Few Arguments?
13 Jan, 2008 - 12:21 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
In main(), you're calling your functions without any arguments. The function calls need to pass the appropriate type of argument and the correct number of arguments:
CODE

int main()
{
  int value1;
  bool value2;
  float value3;
  char body[5];
  tst1(body);     //   <--  passing 1 argument to tst1
  cout << value1 << endl;
  cout << value2 << endl;
  cout << value3 << endl;
  tst2(value1, value2, value3);  //   <--  passing 3 arguments to tst2
  cout << body << endl;
  cin.getline ( body, 5, '\n' );
  cin.get();
}


Remember, the arguments you pass don't necessarily have to have the same name that you've given them in the function definitions - so if you call the functions without arguments, the compiler isn't just going to look for the appropriately named variables elsewhere in the program and stick them in.
User is offlineProfile CardPM
+Quote Post

Delta_Echo
RE: Too Few Arguments?
13 Jan, 2008 - 12:41 AM
Post #3

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 439


My Contributions
Thanks, but for some reason the executable i created won't execute?
Do i have to specify the type of binary file i want to create?

User is offlineProfile CardPM
+Quote Post

VernonDozier
RE: Too Few Arguments?
14 Jan, 2008 - 12:23 AM
Post #4

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 46

Not sure what you mean by specifying what type of binary file. If you look at your original lines:

CODE

tst1();
.
.
.
tst2()


and compare them to jjhaag's lines:

CODE

tst1(body);     //   <--  passing 1 argument to tst1
.
.
.
tst2(value1, value2, value3);  //   <--  passing 3 arguments to tst2


Notice that jjhaag's function calls match the function parameters and yours do not. Also, you do not have any "return" command in either of your functions, each of which had a return type. Thus the program should not compile correctly and no executable will be created. It shouldn't have anything to do with the compile command you use but rather that the program has errors in it.

User is offlineProfile CardPM
+Quote Post

WXY
RE: Too Few Arguments?
14 Jan, 2008 - 06:04 AM
Post #5

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
QUOTE(Delta_Echo @ 13 Jan, 2008 - 01:41 AM) *

Thanks, but for some reason the executable i created won't execute?
Do i have to specify the type of binary file i want to create?

Ill assume the program is not terminating with a OS given error.

If your working in windows, and your double clicking the built .exe to run it, and you have not set for it to hang around after execution concluded then by all means your application opened a window, executed your code, outputted what it should of, concluded it's execution, and then windows closed the window, but it was done too fast for you to see properly. I suggest you put a break point at the main function's return call and then view the window thats frozen, or do something at the end like a 1 million iteration for loop.

This post has been edited by WXY: 14 Jan, 2008 - 06:05 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Too Few Arguments?
14 Jan, 2008 - 08:17 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
If you wish to hold the execution window open for viewing, I'd suggest you shy away from unnecessary loops, and see the following topic:

http://www.dreamincode.net/forums/showtopic30581.htm

It discusses some of the standard methods (and standards compliant) for holding the execution window open.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 05:00AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month