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

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2005
Posts: 2
Reputation: trixiestrat is an unknown quantity at this point 
Solved Threads: 0
trixiestrat trixiestrat is offline Offline
Newbie Poster

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

 
0
  #1
Jan 27th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

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

 
0
  #2
Jan 27th, 2005
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.
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 2
Reputation: trixiestrat is an unknown quantity at this point 
Solved Threads: 0
trixiestrat trixiestrat is offline Offline
Newbie Poster

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

 
0
  #3
Jan 27th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,859
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

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

 
0
  #4
Jan 27th, 2005
>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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2374 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC