Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you get commas into output? Newbie

Status
Not open for further replies.

beth1029

Programmer
Sep 14, 2001
2
US
Question: Write a program that reads 2 integers and prints out their product in a format using commas, we have to use command user interface(CUI). Thank you very much for your help!! Here is what I have:

#include <iostream.h>

void main()

{
long int a; //first integer
long int b ; //second integer
long int c; //product

cout<< &quot;Enter integer:&quot;;
cin>>a;

cout<<&quot;Enter second integer:&quot;;
cin>>b;

c = a*b; //computes product

cout<<c<<endl; //print results with commas

}

 

The following will print a comma after the c variable is printed. I think that's what you're asking.


cout << c << &quot;,&quot; << endl;
 
Brother C, thank you for the reply , but, I wasn't specific enough in what i need - example:
first number might be entered as 345 and second number may be 9864, the product would be 3403080 and i need it to print out 3,403,080
for anyone else that may want to help - this is for visual c++ program (Using CUI). Write a program that reads two integers and prints out their product in a format using commas. I think that I need to use mod somewhere, but I'm not sure. This is what I have so far:

#include <iostream.h>

void main()

{
long int a; // first integer
long int b; //second integer
long int c; //product

cout<< &quot;Enter integer:&quot;;
cin>>a;

cout<<&quot;Enter second integer:&quot;;
cin>>b;

c = a*b; //computes product

cout<<c<<endl; //print product with commas in number

}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top