• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Passing parameters to functions help.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know what that is tat you are talking about?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic