944,103 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 6762
  • C RSS
Oct 8th, 2005
0

type conversion

Expand Post »
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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PeterX is offline Offline
24 posts
since Sep 2004
Oct 8th, 2005
0

Re: type conversion

> 'count' : redefinition; different basic types
What compiler and operating system? And are you compiling as C or C++?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 8th, 2005
0

Re: type conversion

compiler:Micrisoft visual c++ 6
operating system: win xp
I am compiling as C
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PeterX is offline Offline
24 posts
since Sep 2004
Oct 8th, 2005
0

Re: type conversion

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 ?
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Oct 8th, 2005
0

Re: type conversion

>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. }
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 9th, 2005
0

Re: type conversion

Hi again!
Thank you for your help
peter
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PeterX is offline Offline
24 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: monolithic copying
Next Thread in C Forum Timeline: C + Assembler = something I can't solve





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC