I got this assignment for school. I figured out most of it, but one part is really stumping me. The assignment tells you to have the user enter in a dollar amount between $0 and $100, and to give an error message if it's out of the range. I figured all this out after a LOT of trial and error. Here's what I have so far:

#include <iostream>
#include <stdlib.h>

int main()
using namespace std;
char any_key;
double userNumber;
int simple;

cout << "Please enter a dollar amount from $0.00 to $100.00 (no dollar sign): ";
cin >> userNumber;
cout << "\n";

simple = userNumber;
if (userNumber < 0)
cout << "The dollar amount you entered is less than zero! \n";
else if (userNumber > 100)
cout << "The dollar amount you entered is too high! \n";
cout << "You entered " << simple << " dollars and " << (userNumber-simple)*100 << " cents. \n";

cout << "Hit any key to end the program. Thank you!";
cin >> any_key;


But it's the next part that I really don't even know where to start. It says:

Then, go on to tell the user how many of the following
items are required to make up the user amount. Always
give the minimum number of bills and coins, and only use
those listed:



The output after the initial message above, would look
something like this:

"This amount requries 1 twenty, 1 ten, 1 five 1 one,
3 quarters, 2 dimes, 0 nickels and 2 pennies."

I don't even know where to start with this.
Am I supposed to use basic mathemathical expressions and define ints for each unit (ex: int quarters, dimes, nickels, pennies, dollars, fives, tens, twenties), and then add them up to equal the number? We're covering Relational Expressions, Logical Operators, and If/Else statements in this week's lectures. I looked through the notes, but couldn't figure out how to apply them to this part of the assignment.

Please help me--I'm desperate, and it's due tonight.

Please use code tags
Think about it, get a number how many times will twenty go into it. if none then check how many tens, then fives so on and so forth.

I really don't know how I would go about doing that. Would I have to create an int for each individual bill and coin?

>I'm desperate, and it's due tonight.
Sucks for you. I guess you should have paid attention in class.

>I really don't know how I would go about doing that.
You have a dollar amount. Subtract 20 until you can't anymore and count the number of times you subtracted 20. Then subtract 10 until you can't anymore and count the number of times you subtacted 10. Continue to do this until the dollar amount is 0.0.

This isn't a terribly difficult algorithm to figure out. Of course, it's easier to get right if you don't use floating-point variables. They're tricky to work with even for experienced programmers.

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.