Array Help. Please Help me.

Look at this Problem:
Please help me, Figure this out using [TURBO C]

Create a program that will let the user input an amount in the form (367). The Program should determine the no. of coins for each dominations : 50,25,10,5,1.
(using Turbo C)


Last edited on
It would be nice to see some code that you have come up with and then we could help guide you. Right now your looking for the solution which defeats the purpose of the exercise.
Sorry,Actually I don't have an idea. Where Im going to start it. :(
Please help me.
Last edited on
Start at the beginning, and when you come to the end, stop.


a greedy approach may work
Im really sorry. Im not sure about this.

#include <stdio.h>
#include <stdlib.h>

{ int loop_index, Coins[5];
Scores[0] = 50;
Scores[1] = 25;
Scores[2] = 10;
Scores[3] = 5;
Scores[4] = 1;

and then I dont know anymore. what should I do ?
I'm blaming my lazy Professor for not teaching. damn.
dnt blame your teacher ,, just search on loops...
Okay what you have to do is first of all divide amount with 50 then remaing amount with 25 again remaing with 10 and so on...
Last edited on
I normally wouldn't do this but since you did attempt to do something and is completely wrong here is a partial code that you can finish. It will compile and run but doesn't do dimes, nickels, or pennies. And it is apparent you are in the beginning of your learning to code, but that is still no excuse. So take what I have done and finish the code and repost so we can see you are on the right track. I don't want you to get frustrated and quit because the more people we can get coding in this world the better.

To everyone else I'm sure you might get upset with me for posting this much code, but this is a simple problem that by helping him now he might become a better coder later.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

int main()
{
    int num;
    do
    {
     cout << "Give me an integer between 100 - 999 : ";
     cin >> num;
     if(!(num > 100 && num < 999))
     cout << "INVALID ENTRY\n";
    }while(!(num > 100 && num < 999));
    
    const int HALFDOLLAR = 50;
    const int QUARTER = 25;
    const int HOWMANYKINDSOFCOINS = 5;
    //and so on
    
    int arrayToHoldEachAmountOfChange[HOWMANYKINDSOFCOINS];
    string nameOfCoins[HOWMANYKINDSOFCOINS];
    
    arrayToHoldEachAmountOfChange[0] = num / HALFDOLLAR;
    num = num % HALFDOLLAR;
    nameOfCoins[0] = "HalfDollars";
    arrayToHoldEachAmountOfChange[1] = num / QUARTER;
    num = num % QUARTER;
    nameOfCoins[1] = "Quarters";
    //and so on
    
    for(int i = 0; i < HOWMANYKINDSOFCOINS; i ++)
    cout << nameOfCoins[i] << " =" <<  arrayToHoldEachAmountOfChange[i] << endl;
     
    system("pause");
    return 0;
}


Edit: I am only on my fourth month of coding Greedy so I'm sure there are many more ways to this. You can also do the arithmetic within a loop structure just the same.
Last edited on
Thank you for this. I owe my life to you. :) Ill promise I will be a better programmer.
About this code,well, I needed to change it to some turbo C "stuffs". But its fine, I'll handle it. Thank you again. Thank you so much.
*bows* *bows*
Topic archived. No new replies allowed.