Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
void print_line(int index, int cents, int value)
{
    int count = cents / value;
    int dollar_part = value / 100;
    int cents_part = value % 100;
    printf("| %-2d | %9d.%02d | %5d |\n", index, dollar_part, cents_part, count);
}

void coins(int cents)
{
    printf("You did not type in the correct format in terms of dollars and cents.\n");
    printf("Please enter total value: \n");
    printf("+----+--------------+-------+\n");
    printf("| #  | Denomination | Count |\n");
    printf("+----+--------------+-------+\n");
    print_line(1, cents, 10000);
    cents = cents % 10000;
    print_line(2, cents, 5000);
    cents = cents % 5000;
    print_line(3, cents, 1000);
    cents = cents % 1000;
    print_line(4, cents, 500);
    cents = cents % 500;
    print_line(5, cents, 200);
    cents = cents % 200;
    print_line(6, cents, 100);
    cents = cents % 100;
    print_line(7,  cents, 50);
    cents = cents % 50;
    print_line(8, cents, 20);
    cents = cents % 20;
    print_line(9, cents, 10);
    cents = cents % 10;
    print_line(10,cents, 5);
    cents = cents % 5;
    print_line(11, cents, 1);
    cents = cents % 1;


So I've got code that looks like this, there's other code elsewhere but that ain't relevant to my question. What I want to know is how would one go about combining the print line function with the table below? The table is supposed to display how many of each coin is needed to give change, like this:

+----+--------------+-------+
| # | Denomination | Count |
+----+--------------+-------+
| 1 | 100.00 | 0 |
| 2 | 50.00 | 0 |
| 3 | 10.00 | 1 |
| 4 | 5.00 | 0 |
| 5 | 2.00 | 1 |
| 6 | 1.00 | 0 |
| 7 | 0.50 | 0 |
| 8 | 0.20 | 1 |
| 9 | 0.10 | 1 |
| 10 | 0.05 | 0 |
| 11 | 0.01 | 4 |
+----+--------------+-------+


What I have tried:

Honestly, I'm completely lost. I'm unfamiliar with this code so I don't even know where to begin.
Posted
Updated 3-Oct-21 0:52am
v2
Comments
Rick York 3-Oct-21 13:35pm    
Your question is not at all clear. What does "how would one go about combining the print line function with the table below?" mean? This is unclear because one does not "combine" a function with a printed table. Actually, from what I can see, the output you show there was not generated by your code because that's not what your format string does.

To reiterate, what are you actually asking?

Quote:
Honestly, I'm completely lost. I'm unfamiliar with this code so I don't even know where to begin.

And we can't even see the relevant bits - the print_line function is a complete mystery to us so we have even less idea that you do.

If you are unfamiliar with the code, then the first thing to do is ... look at it and works out how it works, what it does, how you tell it to do it.
Then think about exactly what you are trying to achieve and work out how to use the functions to do that.

But at the moment, that looks like poor student grade code that you found on the internet in the hope it would do what your assignment wanted, and you're trying to get others to "fill in the blanks" so you can hand it in. And that isn't going to happen. While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
This is your seventh question on much the same issue. You need to get hold of a good C manual and start learning the language properly. Copying code from the internet in the hope that it will do what you want is just a waste of your time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900