need help with this code

Started by doja, March 22, 2010, 05:59:10 PM

Previous topic - Next topic

doja

/* Exercise 1-2 Starting Solution */
/*

1)   Take the the two variables X and X and change them to
    two other variable names. Make sure your variable names
    are different than your lab partners.  
2)   Change the variable names from "int" to "float"
    observe what happens and record the results via comments.

*/

   
#include <stdio.h>

int main ( void )
{
  float numerator,denominator;  /* define first number */
  /* define second number */
 
  printf( "Enter two numbers: "); /* prompt user */
  scanf( "%f %f", &numerator, &denominator );        /* read values from keyboard */  
 
  /* output results */
  printf( "The sum is %f\n", numerator + denominator );
  printf( "The product is %f\n", numerator * denominator );
  printf( "The difference is %f\n", numerator - denominator );
  printf( "The quotient is %f\n", numerator / denominator );
  printf( "The remainder is %f\n", numerator % denominator );

  return 0; /* indicate successful termination */

} /* end main */
Building main.obj.
E:\Documents and Settings\dee\My Documents\Pelles C Projects\Lab 1-2\main.c(52): error #2168: Operands of '%' have incompatible types 'float' and 'float'.
E:\Documents and Settings\dee\My Documents\Pelles C Projects\Lab 1-2\main.c(52): warning #2234: Argument 2 to 'printf' does not match the format string; expected 'double' but found 'int'.
*** Error code: 1 ***
Done.
/b]

Tsiku

error was because of this line
printf("The remainder is %f\n", numerator % denominator);

im self beginner but here some things what made it work for me

1)
printf("The remainder is %i\n", (int)numerator % (int)denominator);

2)
#include <math.h>

printf("The remainder is %f\n", remainder(numerator,denominator));

doja