I am a beginner to C++, I have an assignment to find all possible ways to give change for any value 10 dollars or less, using $10, $5, $2, $1, .50, .25, .10, .05, .01. I know it needs 9 nested for loops, but I dont have the slightest clue of what to put in them. thanks for any help.
6 1488 Banfa 9,065
Expert Mod 8TB
I am a beginner to C++, I have an assignment to find all possible ways to give change for any value 10 dollars or less, using $10, $5, $2, $1, .50, .25, .10, .05, .01. I know it needs 9 nested for loops, but I dont have the slightest clue of what to put in them. thanks for any help.
Actually it only needs 8 nested loops, the is not loop required for the 0.01 category, it is just everything that is left.
The loops should be nested in order of high values ($10) to low value (0.05), each loop should count from 0 in increments of 1 to indicate the number of a given item.
The stop condition for every loop is the value of the coins counted being greater than then required amount.
Every iteration of the inner most loop will be a result.
Write some code and post it.
Banfa 9,065
Expert Mod 8TB
Sorry my mistake you do need 9 loops I handn't noticed you had already taken 1 off the number of denominations until I wrote a test program.
Are you sure that this is what you have to do, for instance my code produces 53390 different ways of producing the value $5.43 ranging from 543 pennies to $5 + 25c + 10c + 5c + 3 * 1c.
Banfa 9,065
Expert Mod 8TB
And that was with a bug in the program, once fixed it produced 103249 for the value $5.43
Banfa 9,065
Expert Mod 8TB
And when I correct the other bug I get 157589 results for $5.43 and 3237135 results for $10
And when I correct the other bug I get 157589 results for $5.43 and 3237135 results for $10
I was already aware of the things you have said. could you just show me the code. there is 13 ways to do .25, and 50 ways to do .50... thanks
Banfa 9,065
Expert Mod 8TB
I was already aware of the things you have said. could you just show me the code. there is 13 ways to do .25, and 50 ways to do .50... thanks
I could do but I'm not going to because
a. I no longer have it, having understood and solved the problem I deleted it.
b. You wouldn't learn anything if I did, or you will certainly learn a lot more by doing it yourself
Forget about the code, clearly you need to think of the algorithm that you will require to solve this problem, find the algorithm and the code will coming trotting along behind it.
How are you going to decide howmany coins of each type there will be?
What will each level of your nest loops represent?
Take the example of 0.10, this has 4 results
10 * 0.01
1 * 0.05 + 5 * 0.05
2 * 0.05
1 * 0.10
Can you think of a set of instructions that you can follow that will produce this result? In these instructions what initial assumption are you going to make about the number of 0.25?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: chahnaz.ourzikene |
last post by:
Hi all,
This is the first i post in this newsgroup, i hope my english is not too
bad...
Let's get straight to the point ! I have a little probleme using threads in
my little training example :...
|
by: mx2k |
last post by:
Hello @ all,
we have written a small program (code below) for our own
in-developement rpg system, which is getting values for 4
RPG-Characters and doing some calculations with it.
now we're...
|
by: Paolo Tavalazzi |
last post by:
I have a problem on FROM subselect that i don't understand.
I do two query different only for a WHERE clause in a FROM subquery .
1) explain analyze
SELECT DISTINCT ON...
|
by: bitong |
last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
|
by: Dameon99 |
last post by:
my program compiles without problems but when i try to run it pauses shortly and then crashes. When i set it to debug it came up with the following message:
"An Access Violation (Segmentation...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |