I wrote the program and even compiled it using x-code (the included macintosh IDE), but it's outputting strange amounts. Here is the code:
#include <stdio.h>
int main()
{
/*Computes how to pay using the smallest number of each bill*/
int amount;
int n20 = amount/20;
int n10 = ((amount-(n20*20))/10);
int n5 = ((amount-((n20*20)+(n10*10)))/5);
int n1 = ((amount-((n20*20)+(n10*10)+(n5*5)))/1);
printf("Enter the amount to be payed: ");
scanf("%d", &amount);
printf("$20 Bills:%d\n",n20);
printf("$10 Bills:%d\n",n10);
printf("$5 Bills:%d\n",n5);
printf("$1 Bills:%d\n",n1);
return 0;
}
And here is an example of the output:Enter the amount to be payed: Running…
93
$20 Bills:1638
$10 Bills:0
$5 Bills:1
$1 Bills:2
This exercise is from Ch.2 and even though I'm a few chapters ahead of that, I'm still very new. So please, help me out if you know what the heck is happening! And I have a thirst for knowledge so if you want to throw in some more complex stuff, feel free to but please attempt to explain it to me. Thanks
Atlas
Edited by WingedPanther, 10 February 2010 - 08:57 AM.
add code tags (the # button)


Sign In
Create Account

Back to top









