473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

modulus etc

Hi

I know

2000%1000 = 0

What can I do it to print "0" 3 times
000

The above is an exceptional case and simple cases are (this no problem)
2123%1000 = 123

Thanks

Oct 28 '06 #1
5 1286
On Sat, 28 Oct 2006 15:49:16 -0700, 2005 wrote:
Hi

I know

2000%1000 = 0

What can I do it to print "0" 3 times
000

The above is an exceptional case and simple cases are (this no problem)
2123%1000 = 123

Thanks


using namespace std;
cout << fixed << setw(3) << setfill('0') << (2000%1000);
// define fixed field width output
// set the field width
// define a fill character

Oct 28 '06 #2
Hi,

maybe (haven't tested it)

#include <iomanip>

using namespace std;

stream << setfill( '0' ) << setw( 3 ) << setiosflags( ios_base::right ) <<
resetiosflags( ios_base::left )

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"2005" <uw*****@yahoo.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Hi

I know

2000%1000 = 0

What can I do it to print "0" 3 times
000

The above is an exceptional case and simple cases are (this no problem)
2123%1000 = 123

Thanks

Oct 28 '06 #3
2005 wrote:
Hi

I know

2000%1000 = 0

What can I do it to print "0" 3 times
000

The above is an exceptional case and simple cases are (this no
problem) 2123%1000 = 123
Use 'setfill' and 'setw' manipulators.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 28 '06 #4

noone wrote:
On Sat, 28 Oct 2006 15:49:16 -0700, 2005 wrote:
Hi

I know

2000%1000 = 0

What can I do it to print "0" 3 times
000

The above is an exceptional case and simple cases are (this no problem)
2123%1000 = 123

Thanks

using namespace std;
cout << fixed << setw(3) << setfill('0') << (2000%1000);
// define fixed field width output
// set the field width
// define a fill character
Thank you but surprisingly I am getting a strange behaviour - it is
also putting "0" everywhere where there was setw() ???

Could you tell me as to what is that I am not getting it right? Below
is the code (it made no difference even if I put in "fixed" so I took
it off)

while(pCurNode)
{

cout<< setw(1) << setiosflags(ios::left) << ++nCount << ". " << " "
<< setw(30) << setiosflags(ios::left) << pCurNode->m_aName
<< setw(10) << setiosflags(ios::left) << pCurNode->m_nAge
<< setiosflags(ios::left) << pCurNode->m_nSalary/m << ","
<< setw(3) << setfill('0') << pCurNode->m_nSalary%m << endl;
// << setiosflags(ios::left) << (pCurNode->m_nSalary)/m << endl;

pCurNode = pCurNode->m_pLink;

}

Oct 28 '06 #5

2005 wrote:
noone wrote:
On Sat, 28 Oct 2006 15:49:16 -0700, 2005 wrote:
Hi
>
I know
>
2000%1000 = 0
>
What can I do it to print "0" 3 times
000
>
The above is an exceptional case and simple cases are (this no problem)
2123%1000 = 123
>
Thanks


using namespace std;
cout << fixed << setw(3) << setfill('0') << (2000%1000);
// define fixed field width output
// set the field width
// define a fill character

Thank you but surprisingly I am getting a strange behaviour - it is
also putting "0" everywhere where there was setw() ???

Could you tell me as to what is that I am not getting it right? Below
is the code (it made no difference even if I put in "fixed" so I took
it off)

while(pCurNode)
{

cout<< setw(1) << setiosflags(ios::left) << ++nCount << ". " << " "
<< setw(30) << setiosflags(ios::left) << pCurNode->m_aName
<< setw(10) << setiosflags(ios::left) << pCurNode->m_nAge
<< setiosflags(ios::left) << pCurNode->m_nSalary/m << ","
<< setw(3) << setfill('0') << pCurNode->m_nSalary%m << endl;
// << setiosflags(ios::left) << (pCurNode->m_nSalary)/m << endl;

pCurNode = pCurNode->m_pLink;

}
It got fixed when I did (inserted << setfill(' ') at the beginning):
while(pCurNode)
{

if (nCount < 9) {
cout<< setw(1) << setfill(' ') << setiosflags(ios::left) << ++nCount
<< ". " << " "
<< setw(30) << setiosflags(ios::left) << pCurNode->m_aName

Oct 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Watson | last post by:
I'm trying to eliminate some warnings I'm getting -- probably not necessary but it's my final project: I have to use modulus so my variables are int. Is there some way to divide two results and...
2
by: Jim Hunter | last post by:
Hello all, I have been reading K&R2, and it says that "the sign of the result for % machine-dependent for negative operands." Does this mean that the absolute value of the result is...
10
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print...
5
by: Peter Pippinger | last post by:
Hello NG, i need to calculate the modulus with double precisson typed variables. this works well with integers: w1 = w1 % 360; but what do i have to do if i want to use w1 as double? ...
4
by: tvnaidu | last post by:
How to calculate Prescalar and Modulus values for PIT (Programmable Interrupt Timer). I have microcontroller running at 60MHz. I am thinking of writing 1 milli sec ISR for PIT. I need to calculate...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.