hey guys im working on a homework problem..im done with 99% of the problem :|however i cnt figure out how to display my output(which is in dollars) using the comma
my output shows >>160000
how would i make it >>160,000
um should i use setprecision???
please help
thanks:)

So is it:
1. 160 dollar. (one-hundred-sixty)
2. 160.00 dollar (one-hundred-sixty dollar and 00 cents)
3. 160.000 (one-hundred-sixty-thousand)

?

convert the integer to std::string (use stringstream for that), insert the commas, then display the string. There is no function that will do it for you.

If you use C#, VB.NET or C++/CLR you're in luck because WriteLine() can do it.

sorry for not being clear guys...i want to display 160,000 (one-hundred-sixty-thousand)using a comma(,)...
a.dragon>> i am new to c++ so what you saying is use a head file "string" and convert the int variable to string variable ...along with that how would i use this >>std::string<<is this a function??or statement??

#include <string>
#include <sstring>
using std::string;
using std::stringstream;

int main()
{
   int n = 1234567890;
   stringstream str;
   // insert int into stringstream
   str << n;
   // convert to std::string
   string s = str.str();
   // now just insert commas in appropriate places
}

Have you learned anything about converting numbers to strings? Any string manipulation at all? If not, you do not have the knowledge yet. Give it a couple weeks and return to this question. You should have the concepts by then.

thanks again guys..no i havent learned how to convert int to strings ...we just finished the chapter on if statements and teachers output had the comma so i thought maybe there is a function using if statement which allows you to do that..again thanks for the help:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.