| | |
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
![]() |
•
•
Join Date: Jan 2005
Posts: 2
Reputation:
Solved Threads: 0
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.
#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
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
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.
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.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
•
•
Join Date: Jan 2005
Posts: 2
Reputation:
Solved Threads: 0
Re: Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!!
0
#3 Jan 27th, 2005
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.
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
![]() |
Similar Threads
- Homework Help (Python)
- Homework problem (can't figure it out) (C++)
- Problem with very basic homework... (It's done, but have one bug I can't figure out.) (Java)
- Java or PHP? (IT Professionals' Lounge)
- Help with Pointer and While loop Please (C)
Other Threads in the C++ Forum
- Previous Thread: Need some final Touches Help
- Next Thread: Need a touch up Please Help
Views: 2374 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






