Thread: Floor and ceil

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    19

    Question Floor and ceil

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <math.h>
    
    
    int main() {
    
    
        float num1 = 9.97, num2= 3.3333;
    
    
        printf("Rounded number is: %.2f \n", floor(num1[0])); /*Floor just makes the number the same*/
        printf("Rounded number is: %.2f \n", floor(num2[3]));
    
    
        printf("Rounded number is: %.2f \n", ceil(num1)); /*Ceil adds 1 to the number*/
        printf("Rounded number is: %.2f \n", ceil(num2));
        return 0;
    }
    Ahmm I want to round off in the hundredths place but it wont run. Help me please. Arigatogozaimasu. (Yes I'm an otaku but I have a social life okay? No offense.)

  2. #2
    Registered User Ktulu's Avatar
    Join Date
    Oct 2006
    Posts
    107
    The functions floor and ceil work with doubles not floats. Also num1[0] and num2[3] don't exist because they are not arrays.
    This parameter is reserved

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Ktulu View Post
    The functions floor and ceil work with doubles not floats.
    A float will be automatically converted to a double when passed to the function.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by YaZao
    I want to round off in the hundredths place but it wont run.
    Next time, differentiate between "won't run" and "won't compile". In this case it is the latter (though the latter implies the former, but that's besides the point), so you should also have posted the compile errors.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem With ceil() and floor() functions
    By aakashjohari in forum C Programming
    Replies: 10
    Last Post: 01-23-2011, 12:39 AM
  2. floor() and int()
    By lehe in forum C++ Programming
    Replies: 9
    Last Post: 06-16-2009, 03:24 AM
  3. floor
    By jordanguyoflove in forum C Programming
    Replies: 3
    Last Post: 04-01-2009, 09:34 AM
  4. weird errors gcc : functions like floor(), ceil(), sqrt()
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-04-2005, 09:00 AM
  5. weird errors gcc: functions like floor(), ceil(), sqrt()
    By gemini_shooter in forum Linux Programming
    Replies: 2
    Last Post: 06-04-2005, 08:39 AM

Tags for this Thread