NO

Author Topic: need help with this code  (Read 2595 times)

doja

  • Guest
need help with this code
« on: March 22, 2010, 05:59:10 PM »
/* 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]
« Last Edit: March 22, 2010, 07:47:54 PM by doja »

Tsiku

  • Guest
Re: need help with this code
« Reply #1 on: March 22, 2010, 11:30:34 PM »
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

  • Guest
Re: need help with this code
« Reply #2 on: March 23, 2010, 01:32:27 AM »
thanx that worked perfect