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;	
}

Dani AI

Generated

Brief, practical follow-up to the thread: showed a confusing compiler error while returning floating values from a function; correctly spotted a type mismatch, and suggested avoiding name collisions. The steps below help find the real root (name clash vs prototype mismatch) and fix the runtime/precision issues safely.

First, diagnose whether the symbol count is colliding with another declaration or macro in the build. Produce the preprocessed source and search for count so you can see any #define or earlier declaration that changes the meaning:

cl /P source.c        // MSVC: writes preprocessed output to source.i
cl /E source.c > out.i

If compilation produces an object, inspect symbols to see duplicate/conflicting declarations:

dumpbin /symbols source.obj | findstr /I count

If you find another declaration or a macro, change the name to a descriptive identifier or fix the header that introduced it.

Second, make the types explicit and consistent. Converting a floating value to an integer drops the fractional part (truncation toward zero); compilers will warn when you return a double from a function declared to return int. Either change the function to return the floating type that matches the value you compute, or explicitly convert/round to an integer if that is what you want.

Third, tighten compilation to catch problems early. Force C mode or C++ mode deliberately with cl /TC or cl /TP, and enable higher warning levels and warnings-as-errors (/W4 /WX) so mismatches are highlighted. If VC6 is being used, try compiling the same file with a modern toolchain (GCC/Clang or newer MSVC) — newer compilers give clearer diagnostics.

Checklist: search project for duplicate names, inspect preprocessed output for macros, compare prototypes and definitions exactly, pick consistent return types, enable warnings. These steps will resolve the ambiguous error message and prevent subtle conversion bugs.

Recommended Answers

All 5 Replies

> '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.