What am I doing wrong?

This is a discussion on What am I doing wrong? within the C++ Programming forums, part of the General Programming Boards category; Well, it looks right to me... but for some reason, it is not displaying the way I want it to. ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    36

    What am I doing wrong?

    Well, it looks right to me... but for some reason, it is not displaying the way I want it to. Here is the part of the code I am referring to:

    Code:
    	fee=car ( calc);
    
    cout << "You were parked for " << minutes << " minutes.  You owe $" << fee << setprecision(4) << "." << endl;
    As you can see, I am calling the function car () which returns a double value. I DO have fee declaread as double in the function, but it is only displaying the answer from the equations I have it go through. (Ex. ...you owe $9. instead of you owe $9.0000)

    I also DO have #include <iomanip>

    what am i missing?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Put the setprecision before the outputing the fee. And you also need to set the format to ios::fixed. And yes you need to include <iomanip>
    Code:
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
        double fee = 9.00;
            
        std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(2)<<fee<<std::endl;
        
        std::cin.get();
        
        return 0;
    }
    Last edited by prog-bman; 04-21-2006 at 11:07 PM.
    Woop?

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    36
    excellent!!! so simple....

    thnx again!!!!

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    You are very welcome.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

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