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";
else
cout << "You entered " << simple << " dollars and " << (userNumber-simple)*100 << " cents. \n";
cout << "Hit any key to end the program. Thank you!";
cin >> any_key;
return(0);
}
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:
twenties
tens
fives
ones
quarters
dimes
nickels
pennies
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.