Thread: Illegal use of floating point

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    1

    Unhappy Illegal use of floating point

    WAP to convert meters into kilometers and meters.

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main ()
    {
    float ms,kms,tms;
    printf("Enter the total number of meters");
    scanf("%f",&tms);
    kms=tms/1000;
    ms=tms%1000;
    printf("The total number of kilometers and meters are %f kms %f ms",kms,ms);
    getch();
    }
    Getting an error "Illegal use of floating point" Please help me.
    Last edited by Ajay M Katte; 07-10-2014 at 08:38 AM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    modulus of floating point is not supported in most compilers except when using fmod function.

    ms=tms%1000;
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by stahta01 View Post
    modulus of floating point is not supported in most compilers except when using fmod function.
    It's not just compilers. The standard specifies that the modulo (%) operator only works for operands of integral type.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is an Illegal floating point ?
    By everyone0 in forum C Programming
    Replies: 7
    Last Post: 04-27-2010, 09:07 AM
  2. Why illegal use of floating point?
    By chottachatri in forum C++ Programming
    Replies: 2
    Last Post: 03-23-2008, 07:00 AM
  3. Illegal use of floating point...(In C)
    By OmnipotentCow in forum C Programming
    Replies: 5
    Last Post: 05-31-2003, 06:26 PM
  4. Illegal use of floating point
    By Lazy Student in forum C Programming
    Replies: 5
    Last Post: 05-14-2002, 02:10 PM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM