type conversion

Reply

Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

type conversion

 
0
  #1
Oct 8th, 2005
Hi!
I have problem with type conversion.
when I compile the program I get this error:
( 'count' : redefinition; different basic types ).
please tell me about type conversion.


  1. #include<stdio.h>
  2. int count(double houre, double charge);
  3. int main(){
  4. double h=4;
  5. double c=2;
  6.  
  7. printf("%d\n", count(h,c));
  8. return 0;
  9. }
  10. int count(double houre, double charge){
  11. double value;
  12. if(houre<=3.0)
  13. {
  14. return charge;
  15. }
  16. else
  17. {
  18. value=(2+(0.5*(houre-3)));
  19. return value;
  20. }
  21. return 0;
  22. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: type conversion

 
0
  #2
Oct 8th, 2005
> 'count' : redefinition; different basic types
What compiler and operating system? And are you compiling as C or C++?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: type conversion

 
0
  #3
Oct 8th, 2005
compiler:Micrisoft visual c++ 6
operating system: win xp
I am compiling as C
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: type conversion

 
0
  #4
Oct 8th, 2005
int count(double houre, double charge){
    double value;
	 if(houre<=3.0)
                 {
	    return charge;
                 }
	   else 
	 {
	value=(2+(0.5*(houre-3)));
	       return value;
	 }
  return 0;	
}

value is double type and count function is return int type, it is possible ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: type conversion

 
0
  #5
Oct 8th, 2005
>value is double type and count function is return int type, it is possible ?
Yes, but a decent compiler will warn you about a loss of precision.

>compiler:Micrisoft visual c++ 6
Hmm, I'm going to chalk this one up as a "Visual C++ 6 sucks ass" issue. Change the name of your function to something less standard and more meaningful to your intentions:
  1. #include<stdio.h>
  2.  
  3. double calc_charge(double houre, double charge);
  4.  
  5. int main(){
  6. double h=4;
  7. double c=2;
  8.  
  9. printf(".2f\n", calc_charge(h,c));
  10.  
  11. return 0;
  12. }
  13.  
  14. double calc_charge(double houre, double charge){
  15. double value;
  16.  
  17. if(houre<=3.0)
  18. {
  19. return charge;
  20. }
  21. else
  22. {
  23. value=(2+(0.5*(houre-3)));
  24. return value;
  25. }
  26. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 24
Reputation: PeterX is an unknown quantity at this point 
Solved Threads: 0
PeterX PeterX is offline Offline
Newbie Poster

Re: type conversion

 
0
  #6
Oct 9th, 2005
Hi again!
Thank you for your help
peter
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC