Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2012, 03:59 AM
susan12 susan12 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 susan12 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 12 sec
Reputation Power: 0
Beginner C Programming Question

In my introduction to computer programming course i was a given a project asking to create a change maker. Specifically, i must write a program that will make change in coins for any amount up to 99 cents using the fewest possible coins. The program should prompt the user to enter an amount, and then print out the number of each type of coin to make that amount of change. If there are no coins of a particular type, then the program should not print a line for that coin.

Examples:

Enter the change amount: 93
Quarters: 3
Dimes: 1
Nickels: 1
Pennies: 3

Enter the change amount: 89
Quarters: 3
Dimes: 1
Pennies: 4


This is what i have so far. The program works unless the "change" value falls under 25 so i'm assuming the problem involves the "if" statements. I have been stuck for a while and was hoping a misc brah could help me out with some suggestions.


#include <stdio.h>
main ()
{
int change;
int coins;
int remainder;

printf ("Please enter an amount of change from 0-99.\n");
scanf ("%d", &change);

if (change>=25)
{
coins = change/25;
printf ("Quarters: %d\n", coins);
remainder = change%25;
}

if (remainder>=10)
{
coins = remainder/10;
printf ("Dimes: %d\n", coins);
remainder = remainder%10;
}

if (remainder>=5)
{
coins = remainder/5;
printf ("Nickles: %d\n", coins);
remainder = remainder%5;
}

if (remainder>0)
{
printf ("Pennies: %d\n", remainder);
}

}

Reply With Quote
  #2  
Old July 3rd, 2012, 05:57 AM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Dec 2003
Posts: 2,511 ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 m 12 sec
Reputation Power: 2274
Well, just put a little thought into it. If the value of change starts out less than 25, are which of your if statements are going to be executed?
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Beginner C Programming Question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap