0

Hi, I wrote a function as part of a homework assignment, but all it seems to be outputting is 1.#QNAN (I know what this is, I just can't find the cause of it). Here is the function:

double length ( const int a[], int size )
{
       double length = 0;
       for ( int i = 0; i < size; i++ )
       {
           length += pow((double)a[i],2);
       }
       length = sqrt( length );
}

I figure its a stupid mistake, but I just don't see it. Thanks beforehand for an answer!

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by mebob
0

The values of it are prompted in the main function, but i haven't used any numbers larger than 10, or less than 1.

1

Oh this is a silly mistake, your function name and the variable name are the same.
Change one of them. Plus you are not returning anything? Do this :

double length ( const int a[], int size )
{
       double len = 0;
       for ( int i = 0; i < size; i++ )
       {
           len += pow((double)a[i],2);
       }
       return sqrt( len );
}

Edited by firstPerson: n/a

0

What did I say? It was probably a stupid mistake :) Thanks for pointing it out, I never would of noticed if you hadn't.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.