446,234 Members | 1,889 Online
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

# how come no one here uses for loops?

 P: n/a #include #include void centscalculation(int cents, int &count2, int &count7, int &count9) { int Total, diff, mindiff=999999, x, y, z, Nstamp, NewNstamp=999999; //x is for 9cents, y is for 7cents, z is for 2cents; for(x=cents/9; x>=0; x--) { for(y=(cents-x*9)/7; y>=0; y--) { z=(cents-x*9-y*7)/2; Total=(z*2+y*7+x*9); if (Total>=cents) { } else { Total=Total+2; z=z+1; } diff=Total-cents; if (diff>cents; if (cents<0) { cout<<"Error."<
2 Replies

 P: n/a da******@brentwood.bc.ca wrote: We use for loops extensively, what are you talking about. #include No such header in standard C++. int Total, diff, mindiff=999999, x, y, z, Nstamp, NewNstamp=999999; //x is for 9cents, y is for 7cents, z is for 2cents; This isn't even good C coding style. It's retched C++. Declare in the smallest scope they are needed and provide initializers. for(x=cents/9; x>=0; x--) { for(y=(cents-x*9)/7; y>=0; y--) { A commment explaining what the hell it is you're attempting to do here would be nice. Is y really supposed to count to zero here or just down to cents - (x-1)*9? What is your question anyhow? > void main () { The above is illegal in C and C++. > int cents; int count2, count7, count9; while (true) { cout<<"Enter cents, 0 to terminate: "<>cents; You should test to see if this fails. > Mar 8 '07 #2

 P: n/a On Thu, 08 Mar 2007 06:53:38 -0800, davy.zou wrote: Hey! I use for loops! [snip some code with for loops] Wow! so do you! (did I miss the point?) -- Lionel B Mar 8 '07 #3

### This discussion thread is closed

Replies have been disabled for this discussion.