944,165 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2912
  • C++ RSS
Jan 27th, 2005
0

Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!

Expand Post »
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.
Last edited by trixiestrat; Jan 27th, 2005 at 7:28 pm. Reason: Add Code
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
trixiestrat is offline Offline
2 posts
since Jan 2005
Jan 27th, 2005
0

Re: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!

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.
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Jan 27th, 2005
0

Re: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
trixiestrat is offline Offline
2 posts
since Jan 2005
Jan 27th, 2005
0

Re: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need some final Touches Help
Next Thread in C++ Forum Timeline: Need a touch up Please Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC