Hey all,

I am having trouble with a program I am trying to write. Basicially I have a 2 sets of 9 "if statements". These if statements give me the parameters for 3 functions. The problem I am having is that the I am getting errors that are telling me that the parameters for my function are not defined. I am guessing that the function cant see into the "if statements" when I am trying to debug. Unfortunately placing the functions inside the "if statements" is not an option as the program would be very slow, as there is alot of different combinations from the "if statement". Also there is 26 parameters in each function and 16 of these parameters are arrays[22], so saving to text file and reading seems very complex. My friend, a java programmer, sugested I should use "static variables" but as I am new to C++ I am having trouble making sense of how I could implement "static variables" for my problem. Sorry if this all seems abit vague. Any help would be greatly appreciated, at this stage I'm in serious need of sleep :) thanks.
Colm.

Code is worth a thousand people jabbering about how a program works.

Try defining the argument variables (that you are setting in the if stmts and passing to the functions) at the top of the file, making them global:

int arg1;
int argArr1[22];
//...

This is not usually a good design, but if you are just trying to get it to work, and without any more detail (i.e., code), it's all I can offer.

Narue,

Unfortunately the code in question is very large and also I'd get a serious slap on the wrist for putting it on net. I realise this makes answering the issue harder, sorry about that. I'm just looking for any ideas, I dont mind reading up, Im just lost. Thanks.

Colm.

Basically a demo of what I ave is:
[
if(x == 1)
{
double truck1 = gentruck();
// ...... list of things I am generating to run " calc function
}
else if (x == 2)
{
double truck2 = gentruck();
// ...... list of things I am generating to run " calc function
}
// these set of "if statements" continues until
if(x == 18)
{
double truck18 = gentruck();
// ...... list of things I am generating to run " calc function
}

// the output from this set of "if statements" is then used as parameters to calculate my function "cal_load_effects()"

double load_effect = cal_load_effects(parameter1,...parameter26 )/code]

Unfortunately the parameters for my "cal_load_effects()" are coming up as undeclared when I try and run the program. Thanks again for your help.

Colm.

Where are the parameters declared? If your code looks like this then it won't work because the parameters are declared within a nested scope:

if ( condition )
  double param1 = getparam();

if ( condition )
  double param2 = getparam();

function ( param1, param2 );

To correct the problem you'd want to move the declaration to the same scope as the function call and simply assign rather than initialize within the if statements:

double param1;
double param2;

if ( condition )
  param1 = getparam();

if ( condition )
  param2 = getparam();

function ( param1, param2 );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.