Decimal ceil()

This is a discussion on Decimal ceil() within the C++ Programming forums, part of the General Programming Boards category; i have a problem with rounding off or even getting a decimal plce. i am trying to work out the ...

  1. #1
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215

    Decimal ceil()

    i have a problem with rounding off or even getting a decimal plce.

    i am trying to work out the vat on 15 which would be 2.625. not only does the program not out put 2.625 just 2 it wont round off to just 2.63.

    Here is the coding that i am using



    Code:
                    cout << endl;
                    cout<<ceil(17.50/100);
                    cout << endl;
    can anyone help with my problem?

    anything will be a great help thanks

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    1)
    i am trying to work out the vat on 15 which would be 2.625. Here is the coding that i am using
    Code:
                    cout << endl;
                    cout<<ceil(17.50/100);
                    cout << endl;
    Do you expect this:
    Code:
    cout<<ceil(17.50/100);
    to display 2.65? In what number system will you get that result?

    2)Take a look at this:
    Code:
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    
    
    int main() 
    {
    	double vatPercent = 17.5;
    	double vatDec = 17.5/100;
    	
    	double itemPrice = 15.0;
    	double vat = itemPrice * vatDec;
    	
    	cout<<fixed<<setprecision(2)<<vat<<endl;
    
    
        return 0;
    }
    Last edited by 7stud; 04-03-2006 at 10:55 AM.

  3. #3
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    Yeah, thats a great help thanks, got that working,

    just one more problem tho, where it has the "ItemPrice" and it is set at 15.0, how can i make it so it is a value that the user has inputed?

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Basic I/O... not that hard to do:

    Code:
    double itemPrice;
    
    cout << "Enter the price: ";
    cin >> itemPrice;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    Cheers for that,

    I have that working but i have now come (yet again) got another problem, n i have been trying to work it out, it is prob really simple but i now have it to output the sum with the vat added on. i now want to output the sum into a different function eg.

    Code:
    float calculateVAT(float cost)
    
            {
    
                     double vatDec = 17.5/100;
    
                     double itemPrice = cost;
    	         double vat = itemPrice * vatDec + cost;
    
    	        cout<<fixed<<setprecision(2)<<vat<<endl;
            }
    
    void displayOrder(char initials[], char surname[], char address[],
                      char postcode[], int numberOfBottles, float cost,
                      float costPlusVAT, float deliveryCharge,float totalCost, int vat)
    
            {
                    
                    cout <<"Cost Including VAT:         " <<POUND<<vat <<endl;
    
    }
    anyone know what i can do to solve this new problem??


    Thanks

  6. #6
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Strange formatting.

    Code:
    float calculateVAT(float cost)
    why return a float when you don't return a value?? Use Double for passing values.

    The function "calculate" isn't called.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 06:17 PM
  2. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 03:52 AM
  3. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 01:14 AM
  4. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 07:52 AM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 10:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21