0

Possible Duplicate:
Is there a built-in function that comma-separates a number in C, C++, or JavaScript?
How do you set the cout locale to insert commas as thousands separators?

How I could input "commas(,)" to my outputs. for example: $16982 but I need it to look like: $16,982.

Here is my code so far:

#include <iostream> // I/O Stream for form
using namespace std; // to prevent redundance of std

int main() // main to form as integer; begins form
{
            double housing, food, clothing, transportation, education, healthcare, vacations; // Declaring variables for code below as doubles so you can hold a bigger number; decimal values


            // List of expense options that you can choose from
            cout << "                      ----------Yearly Expenses----------"  << endl; // outputs heading to user "yearly expenses"
            cout << "                " << endl; // ends the line and centers the code

            cout << "                            housing          $" ; // outputs housing to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            education        $" ; // outputs education to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            food             $" ; // outputs food to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            clothing         $" ; // outputs clothing to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            transportation   $" ; // outputs transportation to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            healthcare       $" ; // outputs healthcare to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code

            cout << "                            vacations        $" ; // outputs vacations to show user what expenses they can choose from 
            cout << "                " << endl;  // ends the line and centers the code



            cout << "\n\n                         *****Enter your expenses*****" << endl; // outputs heading to user "enter your expenses"


            cout << "\n                                   housing: $"; // outputs to user "heading" 
            cin >> housing; //

            cout << "\n                                   education: $"; // outputs to user "education"
            cin >> education;

            cout << "\n                                   food: $"; // outputs to user "food"
            cin >> food;

            cout << "\n                                   clothing: $"; // outputs to user "clothing"
            cin >> clothing;

            cout << "\n                                   transportation: $"; // outputs to user "transportation"
            cin >> transportation;

            cout << "\n                                   healthcare: $"; // outputs to user "healthcare"
            cin >> healthcare;

            cout << "\n                                   vacations: $"; // outputs to user "vacations"
            cin >> vacations;



            double total; // Declaring variable to hold all of the expenses variables
            total = (housing + education + food + clothing + transportation + healthcare + vacations); // shows "total" equals all expenses variables added together


            cout << "\n\n                       <><><><>total with 23% tax<><><><>" << endl << endl; // Outputs the heading "total with 23% tax" to user

            total = (total * .23) + total; // total equals total multiplied by the 23% to get the percentage tax on your expense
            cout << "                                     $" << total << endl; // outputs the total to the user with the added 23% tax





            system("pause>nul"); 
            return 0; // returns nothing/0

}
Community
  • 1
  • 1
  • Asked and answered here: http://stackoverflow.com/questions/7276826/c-format-number-with-commas – Bukes Feb 03 '12 at 16:53

1 Answers1

0

Well you could try converting your int into a string then format it the way you want...Anyway you just cant insert commas into a int type directly.

ddacot
  • 1,212
  • 3
  • 14
  • 40