473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Stuck at C

3
I'm new at c programming. I've assignment to write codes for count coins in UK Pound notes 5,10,20&50. plz help me as u can
Dec 8 '06 #1
2 1158
I'm new at c programming. I've assignment to write codes for count coins in UK Pound notes 5,10,20&50. plz help me as u can

hi there,

your question is not clear, pls post what the real question, and we eill try to help

regards,
Dec 8 '06 #2
DeMan
1,806 1GB
Do you want to print out a value in the fewest notes/coins possible?
Try something like this (this is fairly simplistic <you could probably use an enum to choose and calculate the values instead of all the if's>but the logic remains the same):
Expand|Select|Wrap|Line Numbers
  1.  
  2. void printMoneyDistribution(int total)
  3. {
  4.    /* counters*/
  5.   int fifties=0; twenties=0; tens=0; fives=0; ones=0;
  6.  
  7.   while(total>0)
  8.   {
  9.     if(total>=50)
  10.     {    
  11.       total=total-50;
  12.       fifties++;
  13.     }
  14.     else  if(total>=20)
  15.     {    
  16.       total=total-20;
  17.       twenties++;
  18.     }
  19.     else  if(total>=10)
  20.     {    
  21.       total=total-10;
  22.       tens++;
  23.     }
  24.     else  if(total>=5)
  25.     {    
  26.       total=total-5;
  27.       fives++;
  28.     }
  29.     else
  30.     {    
  31.       total=total-1;
  32.       ones++;
  33.     }
  34.   }
  35.   printf("%d can be distributed as %d fifties, %d, twenties, %d tens, %d fives %d ones", total, fifties, twenties, tens, fives, ones);
  36. }
  37.  
Dec 9 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: No | last post by:
I purchased a program ( So I thought) that turned out to be just a bunch of php scripts put together. I am getting terrible support from the author but I am biting my tongue because I don't want...
1
by: ron | last post by:
have been stuck on this for several days now. I am trying to create a reverse polish calculator and I'm stuck at an intermediate stage. This is what I know I have to do (just not sure how to do it...
2
by: Vladimir | last post by:
I'm running ASP on IIS 5.1 on Windows XP, the same thing works on Windows 98 with PWS. The function below stuck the IIS - draws only frame with nothing inside and wait for infinite. All other...
3
by: Yeren | last post by:
We run a website with pages that are created using ASP. The website is used by different people from different networks. For some people, the pages are stuck. It looks like the were able to open...
2
by: Bryan Field-Elliot | last post by:
We have a running server (v7.3) which, over time, seems to accumulate a bunch of "stuck" PostgreSQL instances which appear to be dead inside of a transaction. For example, "ps" reveals many of...
8
by: MLH | last post by:
I use a mouse-down procedure to trap right mouse clicks and CTRL-Right mouse clicks. Running the procedure must put honey or some other sticky substance into my keyboard because subsequent...
4
by: Astronomically Confused | last post by:
using System; using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; class HttpProcessor { private Socket s;
4
by: =?Utf-8?B?TWF1cg==?= | last post by:
My cd is stuck in the drive. I can open the drawer O K but the c d will not come out Help me please -- Maur
0
by: =?Utf-8?B?QmlsbEI=?= | last post by:
This is a tough one... My Windows Service app periodically performs some processing on new entries to a SQL Server database table. It uses a simple System.Timer to call the Elapsed event...
7
by: alphasahoo | last post by:
Hi I am working on a program which writes the output a SQL select statements from number of source tables first to a load matrix and then writes to a load.dat file. But while writing to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.