2012-02-03 16 views
0

可能性の重複:
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?どのように入力カンマC++数値出力に

どのようにできた入力 "カンマ(、)" わたしの出力に。たとえば$ 16982ですが、$ 16,982のように表示する必要があります。ここで

私のコードは、これまでのところです:

#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 

} 
+0

質問と回答:http://stackoverflow.com/questions/7276826/c-format-number-with-commas – Bukes

答えて

0

さてあなたは、直接int型へとあなただけのカント挿入コンマとにかく...それをあなたが望むようにフォーマットし、文字列の中にあなたのint型に変換してみてください可能性があります。

関連する問題