# Need some help with looping

• 01-13-2009
Sshakey6791
Need some help with looping
This is a basic version of the programming I'm working on.

Now as most of you can see the output is going to be..... 12345.
But I want it to just print out 5 not 12345.

b/c the program I'm trying to make is that you enter an amount of money and it will give you you're amount of money in pennie, nickel, dime, and quarter.

thanks......
Code:

```#include <iostream> #include <string> using namespace std; int main() {         float pennie = .01;         float nickel = .05;         float dime = .10;         float quarter = .25;         for ( float MoneyEnter = 1.00; MoneyEnter <= 5.00; MoneyEnter++ ) {                 cout << MoneyEnter;         }         return(0); }```
• 01-13-2009
CornedBee
So you loop from 1 to 5, printing the value every time. Now you want to print only 5?

I don't understand the problem.
• 01-13-2009
Guardian
I'm still pretty new to C++ but I think the FOR loop must have a signed integer type for the interater variable.
Look at it from the perspective of trying to interate. Does the computer interate by 1, 0.1, 0.001, 0.0001, etc? You get the idea.
• 01-13-2009
CornedBee
Nope, no such thing. The parts of the for loop can be pretty arbitrary things. The step size is given by the third expression. Note that ++ always means +=1 (unless it's overloaded in weird ways). And yes, that's a bit strange for floating point numbers, but it's just the way the language works.
• 01-13-2009
Guardian
Cool, well I learned something new then but its the first I've ever seen of a float in a For loop.
• 01-13-2009
Sshakey6791
here the program i'm working on
Code:

```#include <iostream> #include <string> using namespace std; int main() {         float MoneyEnter;         float pennie = .01;         float nickel = .05;         float dime = .10;         float quarter = .25;         cout << "Enter amount less then a \$1.00 \n>";         cin >> MoneyEnter;                 return(0); }```
When the user enter in a number less then a dollar it will tell you the number of quarters, dimes, nickels, and pennies needed.
• 01-13-2009
Sshakey6791
That what i was talking about on the top program just in a different way ... :) sorry about the confusion