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.
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.