Look at this Problem:

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. :(
Last edited on
Start at the beginning, and when you come to the end, stop.

a greedy approach may work

#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.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include 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.