How do I display 2 decimal points after a value?

Our professor wants us to display 2 decimal points even if they're both 0. For example if my answer is 1435, it needs to be 1435.00. How Do I go about doing this? Here is my code so far. It is a budget projection program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

void final_print (double new_budget,bool location)
        {
             if (location)
             {cout<<new_budget<<" $ \n";}
             else
             {cout<<"$"<<new_budget<<endl;}  
        }    
bool isValid(char peeked)
        {   
            if(peeked == '1'||peeked== '2'||peeked =='3'||peeked =='4'||peeked =='5'
            ||peeked =='6'||peeked =='7'||peeked =='8'||peeked =='9'||peeked =='0')
            {return false;}
            
            else
            {return true;}

        }       

int main ()

{
    cout << "\t\tWelcome to the Budget Program!";

    bool again;
    char response;
    do

    {
        char dollar_sign2 = '\0';
        char dollar_sign = '\0';

        double budget;
        double spent;
        cout << "\n\nWhat is your budget for the year? ";
        if (isValid(cin.peek()))
        { 
            cin >> dollar_sign;
        }
            
        cin >> budget;
        bool at_end = false;
        if(cin.peek() == '$')
            {at_end=true;}



        cout << "\nHow much have you spent? ";
        if (isValid(cin.peek()))
        { 
            cin >> dollar_sign2;

        }
            
        cin >> spent;
        cin.ignore (INT_MAX,'\n');


        double used = floor((spent/budget)*100+.5);

        //these if else statements will display the percentage used

        if (used > 100)
            {
                cout << "\n\tYou have used " << used << "% of your budget!"

                <<"\n\tYour overspending won't last long in this world!";
            }
        else if (used < 100)
            {
                cout <<"\n\tYou have used "<<used<< "% of your budget!"

                << "\n\tUse the extra money for a vacation, Smith!";
            }
        else // (used == 100)
            {
                cout << "\n\tYou have used "<<used << "% of your budget!"

                << "\n\tHopefully the money was put in the right places!";
            }


        //the next if/else statements will display the new budget
        
         double new_budget;
         if (spent > budget)
            {
                new_budget = ceil(spent/100+.1)*100;
                cout << "\n\nYour new budget for next year will be ";
                final_print(new_budget,at_end);
            }

        else if (spent < budget)
            {
                new_budget = budget;
                cout << "\n\nYou spent less than the budget! Nice! Your budget will remain at ";
                final_print(new_budget,at_end);

            }
  

        cout <<"\n\n\n\t\tWould you like to run this program again? ";
        cin >> response;
        response = tolower(response);
        cin.ignore(INT_MAX,'\n');
        if (response == 'y')
            {
                again = true;
            }
        else
            {
                again = false;

                cout << "\n\n\t\tThanks For Using My Program! Bye!";
            }

    } while (again);
    return 0;
Maybe the setprecision manipulator in <iomanip> would be of interest?
http://www.cplusplus.com/reference/iostream/manipulators/setprecision/

I hope that helps!

-Albatross
Topic archived. No new replies allowed.