• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing parameters to functions help.

 
D Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.
I will try to explain this in as much detail as I can. well here goes.
I am trying to pass "NUMDAYS" as well as the Array "swell_height" to al lthe functions.
but here is the problem, no matter what () i put "swell_hieght,NUMDAYS" into i get all sorts of random erros that range from:
"identifier expected"
" ')' expected"
"loadswell() in SwellHeightsRedone cannot be applied to (int) "

now, to solve this problem I CANNOT USE GLOBAL VARIABLES, and i need to find out where and how to pass the variables.

so thanks in advance.

heres the code:

 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to send values to a method, you need to create a formal parameter list.

This is a list consisting of 0 or more declarations of the form

type formalparametername

If you have more than 1 parameter, you seperate the list by commas.

In order to call the method, you have to form the call and send an actual parameter list that matches each formal parameter in type and position.
 
D Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought so BUT when I type in the code:

//If a in input form user it runs this section
case 'a' :
loadswell(Array swell_height, int NUMDAYS);
break;
case 'b' :
dipswell();
break;
default :


I get all sorts of errors
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because you don't have a version of loadswell that has a formal parameter list that matches in type and position the variables you try to send to the method.

Also when you call a method, you do not include the type of the parameters.
[ May 18, 2006: Message edited by: Keith Lynn ]
 
D Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know what that is tat you are talking about?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing something very basic here: how to write methods that take arguments.

Look at this tutorial, especially at "Calling an Object's Methods": Learning the Java Language - Using Objects

You need to create a method called loadswell that takes parameters. The method will look something like this:

And then you call it by passing it some variables between parentheses. Note, you do not specify the types in the call:
 
D Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahhh thanks man, i knew it was something small like that, but i could not for the life of me remember what had to be done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic