GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Dec-2008, 13:25
branpute branpute is offline
New Member
 
Join Date: Dec 2008
Posts: 4
branpute is on a distinguished road

[Warning] converting to `int' from `double'


I seem to be having some issues with some code i've made for a recent project, and I come here to get some help with it.

I need to get this function to work.. It is supposed to find the median of a given one dimensional array.. but all I get is this error:

Code:
315 C:\Dev-Cpp\Untitled26.cpp [Warning] converting to `int' from `double'

Here is the function code:

CPP / C++ / C Code:
double med(double v[],int n)
{
  int k;
  double median_v;
  //calc mediam
  k = floor(n/2);
  if (n%2 != 0)
  {
     median_v = v[k];
  }
  else
  {
      median_v = ((v[k-1] + v[k])/2);
  )
  return median_v;
}


Any help to make it work, is appreciated.
Last edited by LuciWiz : 14-Dec-2008 at 13:34. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 14-Dec-2008, 13:49
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Function not working.


CPP / C++ / C Code:
k = floor(n/2);
The floor function returns a double by definition:
http://www.cplusplus.com/reference/c...ath/floor.html

It really is not an issue if you mean it to be an integer value.
  #3  
Old 14-Dec-2008, 14:17
branpute branpute is offline
New Member
 
Join Date: Dec 2008
Posts: 4
branpute is on a distinguished road

Re: Function not working.


Quote:
Originally Posted by dlp
CPP / C++ / C Code:
k = floor(n/2);
The floor function returns a double by definition:
www.cplusplus.com

It really is not an issue if you mean it to be an integer value.

ok thanks alot.
  #4  
Old 14-Dec-2008, 14:40
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Function not working.


Quote:
Originally Posted by branpute
ok thanks alot.
Why do you even go to the trouble to use the floor() function? Integer division n/2 gives the same result as floor(n/2), but without the hassle and overhead of a needless and useless function call.

Regards,

Dave
  #5  
Old 14-Dec-2008, 15:00
PowerHouse PowerHouse is offline
New Member
 
Join Date: Nov 2008
Posts: 26
PowerHouse is on a distinguished road
Thumbs up

Re: Function not working.


Quote:
Originally Posted by davekw7x
Why do you even go to the trouble to use the floor() function? Integer division n/2 gives the same result as floor(n/2), but without the hassle and overhead of a needless and useless function call.

Regards,

Dave

I would take his advice, he has ALWAYS been correct when helping me.
  #6  
Old 14-Dec-2008, 16:11
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Function not working.


Quote:
Originally Posted by PowerHouse
I would take his advice...



Thank you for the kind words.

However...

I really, really try not to put out misleading or incorrect information, but everyone screws the pooch from time to time.


In other words, and words, and words:

"Trust, but verify."
---Ronald Reagen

"Don't get all of your information from one place."
---davekw7x

"Do your own research."
---Richard Feynman


Regards,

Dave
  #7  
Old 15-Dec-2008, 16:21
sakisbl sakisbl is offline
New Member
 
Join Date: Dec 2008
Posts: 11
sakisbl is on a distinguished road

Re: [Warning] converting to `int' from `double'


Quote:
I would take his advice, he has ALWAYS been correct when helping me.

I agree. Dave is ALWAYS correct. His knowledge is unbelievable.
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 66 16-Jan-2010 10:53
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 11:57
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 16:19
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:35.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.