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.

#include<stdio.h>
int count(double houre, double charge);
int main(){
     double h=4;
    double c=2;

    printf("%d\n", count(h,c));
    return 0;
}
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;	
}

> 'count' : redefinition; different basic types
What compiler and operating system? And are you compiling as C or C++?

compiler:Micrisoft visual c++ 6
operating system: win xp
I am compiling as C

int count(double houre, double charge){
    [b]double value;[/b]
	 if(houre<=3.0)
                 {
	    return charge;
                 }
	   else 
	 {
	value=(2+(0.5*(houre-3)));
	       [b]return value;[/b]
	 }
  return 0;	
}

value is double type and count function is return int type, it is possible ?

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

#include<stdio.h>

double calc_charge(double houre, double charge);

int main(){
  double h=4;
  double c=2;

  printf(".2f\n", calc_charge(h,c));

  return 0;
}

double calc_charge(double houre, double charge){
  double value;

  if(houre<=3.0)
  {
    return charge;
  }
  else 
  {
    value=(2+(0.5*(houre-3)));
    return value;
  }
}

Hi again!
Thank you for your help
peter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.