Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem returning values from fns - Urgent deadline on the way

Status
Not open for further replies.

robinsql

Programmer
Aug 2, 2002
236
IE
Hi,
I'm new to C and am having trouble returning a value for a fn.

Prototype is the following:

double calculate_data(int amount, char inCurrency[9], char outCurrency[9], double array[5][5]);

An abbreviated version of the fn:

double calculate_data(int amount, char inCurrency[9], char outCurrency[9], double array[5][5])
{
int i, j;
double result=0;
//Find which member of the 2D array to use for the conversion

if (strncmp(inCurrency, "euro", 4) == 0)
{
i=0;
}
if (strncmp(outCurrency, "euro", 4) == 0)
{
j=0;
}
else if (strncmp(outCurrency, "dollar", 6) == 0)
{
j=1;
}
result = (amount * array[j]);
return(result);
}

Lastly this is from the main:
double result=0;
result = calculate_data(amount, inCurrency, outCurrency, array);
printf("The amount equates to %f", result);

The value is fine at the end of the calculate_data function but once I try to get it in main, I am being returned the wrong value. Where am I going wrong? Any help gratefully received.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top